簡體   English   中英

FireFox刪除了我的尾隨“ 0”

[英]FireFox Removes My Trailing '0'

我有一個網頁,在某些字段中顯示存儲在服務器上的值,但如果其他值以“ 0”或“ .00”結尾,則會將其刪除,因此£1.10將是£1.1,£10.00將是£10。

在我的代碼中,我將它們表示為Decimals因此我希望它能顯示整個值。 如果我使用Chrome或IE,對我來說效果很好,那么我的問題就在FF上。

在我看來

<%
    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>
<%} %>

我嘗試將convert.todecimal包裹在我的“和”周圍,但無法正常工作

當我使用F12時,它說我的值是value="30.00"但在我的網頁上它只顯示為30

我嘗試將其用作string ,並嘗試使用string.Format("{0:C}", sum)sum.toString()但我的字段僅不顯示'.00'

Jeroen的評論是正確的。

<%: sum %>切換為<%: sum.ToString("£ 0.00") %>或什至更好: <%: string.Format("{0:C}", sum) %> ,它與語言環境一起使用,使您的字符串格式本地化。

編輯:“ C”是指從CultureInfo繼承的貨幣格式。 這樣可以輕松地本地化您的應用程序。 大多數.Net類重寫.ToString()方法以提供許多不同的格式(特別是數字)。

您應該檢出它們: 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