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
包裹在我的 'sum' 周围,但它不起作用
当我使用 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
我有一个网页,在某些字段中显示存储在服务器上的值,但如果任何其他这些以“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
包裹在我的 'sum' 周围,但它不起作用
当我使用 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