您的位置:首页 > 编程语言 > C#

C#中格式化数字输出,使用NumberFormatInfo.NumberGroupSeparator 属性

2007-10-20 10:53 846 查看
C#

using System;

using System.Globalization;

class NumberFormatInfoSample {

public static void Main() {

// Gets a NumberFormatInfo associated with the en-US culture.

NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;

// Displays a value with the default separator (",").

Int64 myInt = 123456789;

Console.WriteLine( myInt.ToString( "N", nfi ) );

// Displays the same value with a blank as the separator.

nfi.NumberGroupSeparator = " ";

Console.WriteLine( myInt.ToString( "N", nfi ) );

}

}

/*

This code produces the following output.

123,456,789.00

123 456 789.00

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: