//浏览时数字字段转换js函数 2010-9-25
function autoNumByValue(tvalue,i){
tvalue= String(tvalue);
//先把非数字的都替换掉,除了数字和.
tvalue = tvalue.replace(/[^/d.-]/g,"");
//必须保证第一个为数字而不是.
tvalue = tvalue.replace(/^/./g,"");
//保证只有出现一个.而没有多个.
tvalue = tvalue.replace(//.{2,}/g,".");
//保证.只出现一次,而不能出现两次以上
tvalue = tvalue.replace(".","$#$").replace(//./g,"").replace("$#$",".");
tvalue =parseFloat(tvalue).toFixed(eval(i));// Float数据四舍五入到2位小数;
tvalue = formatNum(tvalue,4);
return tvalue;
}
function formatNum(num, digit) //将数字转换成三位逗号分隔的样式
{
if(!/^(/+|-)?(/d+)(/./d+)?$/.test(num)){ return "";}
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("."));
}
浏览页面加载(onload)的时候 先取出<html:text property=""/> 的值 然后调用上面的 autoNumByValue 函数