var stmp_a = "";
function strTrans_a(strT)
{
if(strT.value==stmp_a) return;
var ms = strT.value.replace(/[^\d\.]/g,"").replace(/(\.\d{2}).+$/,"$1");//验证用户的输入
var txt = ms.split("."); //分割成数组
while(/\d{4}(,|$)/.test(txt[0]))
txt[0] = txt[0].replace(/(\d)(\d{3}(,|$))/,"$1,$2"); //科学计数法表示形式
strT.value = stmp_a = txt[0]+(txt.length>1?"."+txt[1]:"");
}这个是我在网上找的 输入 人民币的时候 判断格式的,但这个只判断到2位小数!
我想让它精确到3位小数!应该改哪个地方?
谢谢
function strTrans_a(strT)
{
if(strT.value==stmp_a) return;
var ms = strT.value.replace(/[^\d\.]/g,"").replace(/(\.\d{2}).+$/,"$1");//验证用户的输入
var txt = ms.split("."); //分割成数组
while(/\d{4}(,|$)/.test(txt[0]))
txt[0] = txt[0].replace(/(\d)(\d{3}(,|$))/,"$1,$2"); //科学计数法表示形式
strT.value = stmp_a = txt[0]+(txt.length>1?"."+txt[1]:"");
}这个是我在网上找的 输入 人民币的时候 判断格式的,但这个只判断到2位小数!
我想让它精确到3位小数!应该改哪个地方?
谢谢
试试:
var ms = strT.value.replace(/[^\d\.]/g,"").replace(/(\.\d{3}).+$/,"$1");
var ms = parseFloat(strT.value.replace(/[^\d\.]/g,"")).toFixed(3);