function formatNum(num) //将数字转换成三位逗号分隔的样式
{
if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){alert("wrong!"); return num;}
var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");
while(re.test(b)) b = b.replace(re, "$1,$2$3");
return a +""+ b +""+ c;
}
alert(formatNum(-12345678.123));
alert(formatNum("12345678.123"));
alert(formatNum("10000000000000000000000000000000000000000"));
{
if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){alert("wrong!"); return num;}
var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");
while(re.test(b)) b = b.replace(re, "$1,$2$3");
return a +""+ b +""+ c;
}
alert(formatNum(-12345678.123));
alert(formatNum("12345678.123"));
alert(formatNum("10000000000000000000000000000000000000000"));
解决方案 »
- jquery 对ul下的多个li进行分页<ul><li></li><li></li><li></li><li></li></ul>
- 网页的联动显示问题
- javascript 控制hyperlink代码
- 紧急求助:为什么jsp页面同一条记录会多次显示?不明白啊
- 怎么样用javascript取XML标签的值?
- 关于全局变量的问题!
- 请教:C#程序中执行confirm语句的问题
- 怎样学习从C/S转变为 B/S 的开发!!我是一个初学者,希望高手指明一条道!!
- 关于页面中命令按钮的问题
- 新人求助在JS里面如何实现对TABLE的首列进行固定?
- 还是下拉框问题,怎么到这里就出错,改z-index=-1,就看不见了?
- 一个送分的问题js
alert(formatNum("1.00000000000000000000000000000000000000001"));
{
if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){alert("wrong!"); return num;}
var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");
while(re.test(b)) b = b.replace(re, "$1,$2$3");
if (c && digit && new RegExp("^.(\\d{"+ digit +"})(\\d)").test(c)){
if (RegExp.$2>4) c = (parseFloat(RegExp.$1)+1)/Math.pow(10, digit);
else c = "."+ RegExp.$1;}
return a +""+ b +""+ (c+"").substr((c+"").indexOf("."));
}
alert(formatNum(-12345678.005, 2));
alert(formatNum("12345678.1256246", 6));
alert(formatNum("10000000000000000000000000000000000000000"));
function formatNum (str, n)
formatNum = FormatNumber(str,n)
end function
</script>
<script>
alert(formatNum("12345678.1256246", 2))
</script>
{
if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){alert("wrong!"); return num;}
var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");
while(re.test(b)) b = b.replace(re, "$1,$2$3");
if (c && digit && new RegExp("^.(\\d{"+ digit +"})(\\d)").test(c)){
if (RegExp.$2>4) c = (parseFloat(RegExp.$1)+1)/Math.pow(10, digit);
else c = "."+ RegExp.$1;}
return a +""+ b +""+ (c+"").substr((c+"").indexOf("."));
}
//alert(formatNum(-12345678.005, 2));
//alert(formatNum("12345678.1256246", 6));
//alert(formatNum("10000000000000000000000000000000000000000"));
var mm=1;
function imgzoom(h)
{
if (h==1)
{
mm+=0.2;
mm=formatNum(Math.min(2,mm),2);
document.all.imgjpg.style.zoom=mm;
window.htm_all.style.zoom=mm;
alert(mm*100+"%");
}
else if(h==2)
{
mm-=0.2;
mm =formatNum(Math.max(0.05, mm),2);
document.all.imgjpg.style.zoom=mm;
window.htm_all.style.zoom=mm;
alert(mm*100+"%");
//document.body.style.zoom=mm;
}
}
可是这样会报错
关注这个问题。对了。楼上的哥们,是JAVA脚本