Blazor格式化数字的InputType [英] Blazor format an InputType of Numeric

查看:67
本文介绍了Blazor格式化数字的InputType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人会知道如何将数值类型格式化为看起来像100.10吗?当前,如果该值为100.10,它将显示为100.1

Would anyone know how to format a Numeric type to look like 100.10? Currently if the value is 100.10 it will display as 100.1

尝试使用C2,0:0.##的@ bind-value:format,我是Blazor的新手,所以如果有人可以向我指出正确的方向,将不胜感激.

tried @bind-value:format with C2, 0:0.##, I'm new to Blazor so if anyone could point me in the right direction it would be appreciated.

<BSBasicInput InputType="InputType.Number" @bind-Value="@Amount" step="0.01" />

推荐答案

如果绑定到 decimal ,它似乎将保留为该值指定的小数位数,甚至可以训练零./p>

If you bind to a decimal it seems it will keep the number of decimals you specify for the value, even training zeros.

@page "/"
<EditForm Model=@Account>
    <InputNumber @bind-Value=Account.Balance/>
    <button>Submit</button>
</EditForm>

@code
{
    BankAccount Account = new BankAccount();

    public class BankAccount
    {
        public decimal Balance { get; set; } = 23.300;
    }
}

对于彩车和双打,我希望以下内容能发挥作用

For floats and doubles I would have expected the following to work

<InputNumber @bind-Value=Account.Balance @bind-Value:format="F2"/>

但是似乎只支持 DateTime DateTimeOffset ,这很遗憾.

But it seems only DateTime and DateTimeOffset are supported, which is a shame.

在Blazor University上有一个示例,展示了如何从 InputBase 降级以创建自己的输入控件.实现一个采用该格式的控件将是非常简单的.

There is an example on Blazor University showing how to descend from InputBase to create your own input controls. It would be quite trivial to implement a control that honours the format.

https://blazor-university.com/forms/descending-from-inputbase/

这篇关于Blazor格式化数字的InputType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆