Format decimal value to string with leading spaces

后端 未结 4 896
鱼传尺愫
鱼传尺愫 2020-12-14 14:39

How do I format a decimal value to a string with a single digit after the comma/dot and leading spaces for values less than 100?

For example, a decimal value of

4条回答
  •  忘掉有多难
    2020-12-14 15:04

    All above solution will do rounding of decimal, just in case somebody is searching for solution without rounding

    decimal dValue = Math.Truncate(1.199999 * 100) / 100;
    dValue .ToString("0.00");//output 1.99
    

提交回复
热议问题