fomat string with 2 decimal places

  • Thread starter Thread starter soni2926
  • Start date Start date
S

soni2926

hi,
i have the following being returned to be in a string:
20.5
i need to make this with 2 places after the decimal, like 20.50,
anyway to do that? I've tried the following but it doesn't seem to be
working:
string newstring = string.Format("{0:#.##}", price.ToString());

price is of type Object.

Thanks.
 
i have the following being returned to be in a string:
20.5
i need to make this with 2 places after the decimal, like 20.50,
anyway to do that? I've tried the following but it doesn't seem to be
working:
string newstring = string.Format("{0:#.##}", price.ToString());

price is of type Object.

You're trying to format a string as if it were a number. Try just
removing the call to ToString().
 
hi,
i have the following being returned to be in a string:
20.5
i need to make this with 2 places after the decimal, like 20.50,
anyway to do that? I've tried the following but it doesn't seem to be
working:
string newstring = string.Format("{0:#.##}", price.ToString());

price is of type Object.

The ToString() can apply formatting itself.

price.ToString("0.00") and may other forms of formatting currency, numeric
data with decimals, dates etc, ect.

Use Google and look it up if you like.
 
Back
Top