using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Decimal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Test();
}
private void Test()
{
decimal mydcm = 12.3456m;
Response.Write("货币格式:"+mydcm.ToString("c")+"<br>");
Response.Write("科学技术法:"+mydcm.ToString("e") + "<br>");
Response.Write("浮点数:" + mydcm.ToString("f3") + "<br>");
Response.Write("常规格式:" + mydcm.ToString("g") + "<br>");
Response.Write("数字格式:" + mydcm.ToString("n") + "<br>");
Response.Write("百分比格式:" + mydcm.ToString("p3") + "<br>");
Response.Write("自定义格式:" + mydcm.ToString("#.000") + "<br>");
}
}
输出结果:
货币格式:¥12.35
科学技术法:1.234560e+001
浮点数:12.346
常规格式:12.3456
数字格式:12.35
百分比格式:1,234.560%
自定义格式:12.346