简体   繁体   English

用千位分隔符转换格式化的十进制字符串

[英]convert formatted decimal string with thousand seperator

I could not find answer which combines the two here. 我找不到将两者结合的答案。

I am getting from the database for example 8120.349 and looking to convert this to two decimal and thousand seperator. 我从数据库8120.349中获取信息,并希望将其转换为两位十进制和千位分隔符。 so ideal output string I am looking for here is 8,120.35 所以我在这里寻找的理想输出字符串是8,120.35

Currently I am converting to two decimal using 目前我正在使用转换为两位十进制

MaxValue.ToString("F2") //maxvalue is decimal

this outputs me 8120.35 这输出了我8120.35

tried adding this for thousand seperator after looking at few answers. 在看了几个答案后尝试将其添加为千位分隔符。

String.Format("{0:n}", MaxValue.ToString("F2"))

this still gives me same output. 这仍然给我相同的输出。

any ideas here? 这里有什么想法吗?

You could use MaxValue.ToString("N2") 您可以使用MaxValue.ToString("N2")

Fiddle: https://dotnetfiddle.net/uEBlPA 小提琴: https : //dotnetfiddle.net/uEBlPA

You should use : Standard Numeric("N") Format Specifier 您应该使用: 标准数字(“ N”)格式说明符

double number = 8120.349;

var stringFormatted = number.ToString("n");

您也可以使用手工制作的格式,

string.Format("{0:#,##0.00}", 8120.349)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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