Number原生类型的扩展
数值和字符串之间的转换
字符串 数值
Number.parseLocale(value)
Number.parseInvariant(value)
数值 字符串
Number.prototype.format(format)
Number.prototype.localeFormat(format)
字符串 数值
Number.parseLocale(value)
Number.parseInvariant(value)
数值 字符串
Number.prototype.format(format)
Number.prototype.localeFormat(format)
localeFormat和parseLocale方法
需要将EnableScriptGlobalization属性设为true
浏览器中设置的语言文化
可以通过设置Page.Culture来改变
格式信息会输出到页面中
parseInvariant和format方法
相当于语言环境为en-US
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" />
<div id="info"></div>
<script language="javascript" type="text/javascript">
function display(text)
{
document.getElementById("info").innerHTML += (text + "<br />");
}
var num = 12345678.12345678;
display("num.format('p') = " + num.format("p"));
display("num.format('d') = " + num.format("d"));
display("num.format('c') = " + num.format("c"));
display("num.format('n') = " + num.format("n"));
display("--------------")
display("num.localeFormat('p') = " + num.localeFormat("p"));
display("num.localeFormat('d') = " + num.localeFormat("d"));
display("num.localeFormat('c') = " + num.localeFormat("c"));
display("num.localeFormat('n') = " + num.localeFormat("n"));
</script>
</form>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" />
<div id="info"></div>
<script language="javascript" type="text/javascript">
function display(text)
{
document.getElementById("info").innerHTML += (text + "<br />");
}
var num = 12345678.12345678;
display("num.format('p') = " + num.format("p"));
display("num.format('d') = " + num.format("d"));
display("num.format('c') = " + num.format("c"));
display("num.format('n') = " + num.format("n"));
display("--------------")
display("num.localeFormat('p') = " + num.localeFormat("p"));
display("num.localeFormat('d') = " + num.localeFormat("d"));
display("num.localeFormat('c') = " + num.localeFormat("c"));
display("num.localeFormat('n') = " + num.localeFormat("n"));
</script>
</form>