需要了解的命名空間及類:
System.Globalization;
CultureInfo;
NumberFormatInfo;
using System;
using System.Globalization;
class NumberFormatInfoSample {
public static void Main() {
NumberFormatInfo nfi = new CultureInfo( "pl-PL", false ).NumberFormat;
double aa = 12.234;
Console.WriteLine( aa.ToString( "N", nfi ) );
string strNo = "12,234";
double fNo = double.Parse(strNo, nfi);
Console.WriteLine( fNo.ToString( "N", nfi ) );
}
}
/*
This code produces the following output.
12,23
12.234
*/
注:
1、在波蘭、德國等國家區域環境下,小數點是由“,”表示的(有點另類哈)。
2、Java裡也有類似情況,需要了解的包:
import Java.text.Numberformat;
import Java.util.Locale;
Numberformat nf2 =
Numberformat.getInstance(Locale.GERMAN);
System.out.println(nf2.format(1234.56));