william007 william007 - 1 year ago 109
C# Question

Convert string to 2 decimal place

I have a string (confirm to be of decimal expression)

I want to convert to a string with two decimal place

How should I do in C#?

Answer Source
var probablyDecimalString = "0.4351242134";
decimal value;
if (Decimal.TryParse(probablyDecimalString , out value))
    Console.WriteLine ( value.ToString("0.##") );
    Console.WriteLine ("not a Decimal");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download