简体   繁体   English

FireFox删除了我的尾随“ 0”

[英]FireFox Removes My Trailing '0'

I have a web page which in some fields displays values stored on a server but if any other these end with '0' or '.00' it removes them so £1.10 would be £1.1 and £10.00 would be £10. 我有一个网页,在某些字段中显示存储在服务器上的值,但如果其他值以“ 0”或“ .00”结尾,则会将其删除,因此£1.10将是£1.1,£10.00将是£10。

In my code I have them as Decimals so I would have expected it to show the entire values. 在我的代码中,我将它们表示为Decimals因此我希望它能显示整个值。 If I use Chrome or IE it works fine for me, my issue is just with FF. 如果我使用Chrome或IE,对我来说效果很好,那么我的问题就在FF上。

In my view 在我看来

<%
    Decimal sum = 0;
    Decimal totalTrancheValues = 0;
    var isCappeddrawdown = false;

    foreach (var tranche in benefitDetails.Tranches)
    {
        //Adds all remaining incomes for 'Capped drawdown' and give a total for them all
        if (tranche.FundType == "Capped drawdown")
        {
            sum = sum + Convert.ToDecimal(tranche.GrossIncomeRemainingThisPensionYear == null ? 0 : tranche.GrossIncomeRemainingThisPensionYear);
            isCappeddrawdown = true;
        }

        //Adds totals for all tranches
        totalTrancheValues = totalTrancheValues + Convert.ToDecimal(tranche.Value == null ? 0 : tranche.Value);
    }
%>

<div class="form-group">
     <label class="col-sm-offset-1 col-sm-4 control-label">SIPP cash balance</label>
     <div class="col-sm-4">
          <input id="SIPPCashBalance_Textbox" name"SIPPCashBalance_Textbox" value=<%: Math.Round(client.Sipp.Cash, 2) %> disabled />
     </div>
</div>
<% if (isCappeddrawdown)
{%>
     <div class="form-group">
          <label class="col-sm-offset-1 col-sm-4 control-label">Remaining income</label>
          <div class="col-sm-4">
               <input id="RemainingIncome_Textbox" name="RemainingIncome_Textbox" value=<%: sum %> disabled />
          </div>
     </div>
<%} %>

I tried wrapping convert.todecimal around my 'sum' but it just will not work 我尝试将convert.todecimal包裹在我的“和”周围,但无法正常工作

When I use F12 it says my value is value="30.00" but on my webpage it displays only as 30 当我使用F12时,它说我的值是value="30.00"但在我的网页上它只显示为30

I have tried using it as a string and have tried string.Format("{0:C}", sum) and sum.toString() but my field just will not display the '.00' 我尝试将其用作string ,并尝试使用string.Format("{0:C}", sum)sum.toString()但我的字段仅不显示'.00'

Jeroen comment is correct. Jeroen的评论是正确的。

Switch <%: sum %> to <%: sum.ToString("£ 0.00") %> or even better: <%: string.Format("{0:C}", sum) %> , which works with locale, making your string format localized. <%: sum %>切换为<%: sum.ToString("£ 0.00") %>或什至更好: <%: string.Format("{0:C}", sum) %> ,它与语言环境一起使用,使您的字符串格式本地化。

Edit: The "C" refers to a Currency format, which inherits from the CultureInfo. 编辑:“ C”是指从CultureInfo继承的货币格式。 That makes it easy to localize your application. 这样可以轻松地本地化您的应用程序。 Most .Net classes override the .ToString() method to supply many different formats (specially numbers). 大多数.Net类重写.ToString()方法以提供许多不同的格式(特别是数字)。

You should check'em out: https://msdn.microsoft.com/pt-br/library/fzeeb5cd(v=vs.110).aspx 您应该检出它们: https ://msdn.microsoft.com/pt-br/library/fzeeb5cd(v = vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM