![](/img/trans.png)
[英].NET String formatting -What does the # mean to the left of the decimal point?
[英]Is there a formatting expression I can use to insert a decimal point into a string?
我有一个包含ICD9代码作为值之一的转发器:
<asp:Repeater runat="server" ID="rptDRGGrouper">
<HeaderTemplate>
<table>
<tr>
<th>ICD9 Code</th>
<th>Description</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem, "ICD9Code").ToString()%></td>
<td><%#DataBinder.Eval(Container.DataItem, "Description").ToString()%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
这里的ICD9代码没有格式。 我想添加一些,以便
V5789 // current output
V57.89 // desired output
应在第三个字符后添加小数(如果有第四个字符)。 例如
496 becomes 496 // no change
3051 becomes 305.1
v5789 becomes v57.89
从表面上看,我将为此创建扩展方法:
public static class Extensions
{
public static string ICD9Format(this string input)
{
//check easy cases first
if (string.IsNullOrEmpty(input) || input.Length <= 3)
{
return input;
}
return input.Insert(3, ".");
}
}
然后,使用它:
<td>
<%#DataBinder.Eval(Container.DataItem, "ICD9Code").ToString().ICD9Format()%>
</td>
假设没有其他特殊的格式规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.