【问题标题】:How to format decimal in c# asp-format tag to 2 decimal points and without trailing zeros if it is an int?如何将 c# asp-format 标记中的小数格式化为 2 个小数点,如果它是 int,则不带尾随零?
【发布时间】:2018-07-14 12:43:06
【问题描述】:

如何将 c# asp-format 标签中的小数格式化为 2 个小数点,如果是 int,则不带尾随零?

<input asp-for="X" asp-format="{0:0.00}" />

我需要:

123.456 => 123.46
123.45  => 123.45
123.4   => 123.40
123     => 123

谢谢

【问题讨论】:

    标签: c# razor format asp.net-core-mvc decimal


    【解决方案1】:

    试试这个

    asp-format="{0:0.##}"

    【讨论】:

    • 我认为这不会将 123.4 格式化为 123.40。我怀疑你需要自己做这件事。如果数字等于转换为整数的数字,则将其呈现为整数。如果不是,则用两个小数点渲染
    • @Flydog57,但这不仅仅是输出,它是表单输入
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    相关资源
    最近更新 更多