First of all this is not a duplicate question my need is to have 2 precision decimal always
e.g.
2 should be converted as 2.00
0 should be converted as 0.00
0.5 should be converted as 0.50
output number has to be decimal
Things i had tried
decimal val = 0.5000M
decimal d = Math.Round(val, 2);//gives 0.5 i need 0.50
NOTE: I am not looking to convert decimal to string as i need to send it as a soap request which accepts decimal value only, so i dont have flexibility to convert it to string.
Update below code as answered by Jakub Lortz works fine though it may look complex
solution 1 by Jakub Lortz
decimal twoPoint00 = new Decimal(200, 0, 0, false, 2);
decimal twoPoint0 = new Decimal(20, 0, 0, false, 1);
Console.WriteLine(twoPoint00) // prints 2.00
Console.WriteLine(twoPoint0) // prints 2.0
solution 2 by Bogdan
he had given very simple solution which will also work
decimal val = 0.5000M;
string result = string.Format("{0:f2}", val);
decimal d;
Decimal.TryParse(result, out d);