简体   繁体   中英

Format decimal number c#

Is there a way to format, lets say, this number 36.9308706956375 into 36,930.87? I tried all kind of pattern including the one below it doesn't seem to work.It return 36,93.

decimal dec = 36.9308706956375;
var num = String.Format(CultureInfo.GetCultureInfo("ro-RO"), "{0:#,##0.00}", dec);

Thanks

It doesn't make sense to format 36.9308706956375 with thousands operator so I had to multiply it by 1000

(36.9308706956375 * 1000).ToString("N2")

Or

String.Format("{0:N2}", 36.9308706956375 * 1000)

More numeric formats can be found here in the official docs .

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