【问题标题】:A floatting point value will have 2 digits after the decimal place and will occupy 8 places浮点数小数点后有 2 位,占用 8 位
【发布时间】:2022-11-22 06:40:42
【问题描述】:

假设,我有一个浮点值 [-12.3456]。我想像 [ -12.34] 那样展示它。

我写了以下内容:

    public override string ToString()
    {
        return $"{x:0.00, 8}{y:0.00, 8}{z:0.00, 8}";
    }

但是,输出不是我所期望的。

我怎样才能做到这一点?

【问题讨论】:

    标签: c#


    【解决方案1】:

    我找到了答案:

    using System;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            Console.WriteLine ("[{0, 10:0.00}]", -12.3456);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-09
      • 1970-01-01
      • 2011-09-15
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      • 2013-09-12
      • 1970-01-01
      相关资源
      最近更新 更多