【问题标题】:Incorrect decimal point position小数点位置不正确
【发布时间】:2018-12-21 11:56:49
【问题描述】:

我有一个文本框,我想在其中输入格式为“1.5”的值,当我在文本框中输入“1.5”时,“15.00”会保存到我的数据库中。该值应接受用户的逗号和小数,但小数点的位置需要在第一个数字(1.5)之后,并且 GridView 上显示的分隔符需要是点但它显示逗号。

这是我的文本框。

<asp:TextBox ID="txtCase" runat="server" Width="90px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCase" runat="server" ControlToValidate="txtCase"
    ErrorMessage="Required" ForeColor="Red" Display="Dynamic" ValidationGroup="Insert"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revCase" runat="server" ErrorMessage="Decimal Field"
    ControlToValidate="txtCase" ForeColor="Red" ValidationExpression="^\d+([,\.]\d{1,2})?$"></asp:RegularExpressionValidator>

我试过了:

how to decrease decimal places in gridview column asp.net C#

format a number with commas and decimals in C# (asp.net MVC3)(这是 C#,但我更喜欢使用我的 .aspx 文件)。

我也尝试将这些添加到我的文本框中。

DataFormatString="{0:0.00}"
DataFormatString="{0:0.0}"

但不幸的是没有运气。

我不确定我还能改变什么,我在 Stack Overflow 上找到的大多数文章都是关于小数点之后的。

所以简而言之,我需要插入 1.5 而不是 15.00,并且我需要我的 GridView 来显示点而不是逗号作为分隔符。

GridView 列

<asp:BoundField DataField="Cases" SortExpression="Cases" HeaderText="Cases" Visible="true"
 ReadOnly="true" ItemStyle-HorizontalAlign="Center"/>

有什么想法吗?

【问题讨论】:

    标签: asp.net vb.net textbox decimal-point


    【解决方案1】:

    添加

    Culture="en-US"
    

    进入

    <%@ Page
    

    .aspx 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多