471,571 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,571 software developers and data experts.

fomat string with 2 decimal places

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.

Jul 10 '07 #1
2 9156
<so******@yahoo.comwrote:
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().

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 10 '07 #2

<so******@yahoo.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
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.

Jul 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brent Bortnick | last post: by
1 post views Thread by Gizmo | last post: by
1 post views Thread by MAF | last post: by
3 posts views Thread by David | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.