国际化数字格式输出(C#版)

需要了解的命名空间及类:

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));


 

你可能感兴趣的:(java,String,C#,System,Class,import)