简体   繁体   中英

How to format a string with 1000s separator and zeros after comma in C#

I want to format a string with 1000's separator and also two decimal places by default

I tried this one but it's not working as it fails to append two zeros when there are no decimals

String.Format("{0:#,##0.##}", money); //I want something like 1000.23 and also 1000.00

Just to be sure you're not making this more complicated then necessary

String.Format("{0:f2}", money);

Maybe standard number format is enough and custom number format is not needed. But as mentioned if your Culture has a , as seperator, this won't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM