Format decimal value to string with leading spaces

后端 未结 4 892
鱼传尺愫
鱼传尺愫 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:01

    Another one with string interpolation (C# 6+):

    double x = 123.456;
    $"{x,15:N4}"// left pad with spaces to 15 total, numeric with fixed 4 decimals
    

    Expression returns: " 123.4560"

提交回复
热议问题