• # How to add Decimal Zeros to a integer(whole) number(if value 123 is should be 123.00)

Below code is working these condition , that is

if 1.0 is ==1.10
if .1 is ==0.10
if 111.2222 is == 111.20

MyCode:
string val = "1234.22";
if (val.Split('.').Length > 2)
{
val = val.Split('.') + '.' + val.Split('.').Substring(0, 1);
}
decimal d = Convert.ToDecimal(val);
string result = d.ToString("0.00");
but i want to add one more condition instead in my code that is
If i give value = 123 it should be 123.00 that's all
if 123 is == 123.00
i cant able to done this. so help me to add that condition instead of my code.

thanking with
Paul.S
• It is the same technique . Try the following code if you desire.

Code:

decimal x = 12;
string result2 = x.ToString("0.00");
if (x == Decimal.Parse(result2))
{
Console.WriteLine("Result 2 = " + result2);
}

Output:

Result 2 = 12.00.

Paul.S

use
`decimal sz = 23;string output = sz.ToString("#.##")//output will be 23.00ORdecimal val = 23;twoDec = Math.Round(val, 2);//output will be 23.00//even you call string.Format it will not change original value . but it will return formatted string. so try below decimal szval = 23;string szout = string.Format("{0:0.00}", szval));`

Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]

• Hi
Paul
try this code

string num = "123";
if (!num.Contains("."))
{
string a = num +".00";
}
else
{
string b = "1";
}

Name : Dotnet Developer-2015
Email Id : kumaraspcode2009@gmail.com

'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

• Thanks for all of your valuable and quick replies dear friends.
almost i complete the project with all of your help.

Paul.S

• `if(num.Equals('.'){}else{ num = num+".00";}`
SRI RAMA PHANI BHUSHAN KAMBHAMPATI