使用自定义数字格式
NumberFormatInfo
可用于格式化整数和浮点数。
// invariantResult is "1,234,567.89"
var invarianResult = string.Format(CultureInfo.InvariantCulture, "{0:#,###,##}", 1234567.89);
// NumberFormatInfo is one of classes that implement IFormatProvider
var customProvider = new NumberFormatInfo
{
NumberDecimalSeparator = "_NS_", // will be used instead of ','
NumberGroupSeparator = "_GS_", // will be used instead of '.'
};
// customResult is "1_GS_234_GS_567_NS_89"
var customResult = string.Format(customProvider, "{0:#,###.##}", 1234567.89);