Decimal group seperator for the fractional part

后端 未结 3 1230
误落风尘
误落风尘 2021-01-28 07:27

I wonder what would be the best way to format numbers so that the NumberGroupSeparator would work not only on the integer part to the left of the comma, but also on

3条回答
  •  抹茶落季
    2021-01-28 08:16

    OK, not my strong side, but I guess this may be my best bet:

     string input = Math.PI.ToString();
     string decSeparator = System.Threading.Thread.CurrentThread
                          .CurrentCulture.NumberFormat.NumberGroupSeparator;
     Regex RX = new Regex(@"([0-9]{3})");
     string result  = RX.Replace(input , @"$1" + decSeparator);
    

    Thanks for listening..

提交回复
热议问题