当柳上原的风吹向天际的时候...

真正的快乐来源于创造

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>
<input id="decimalTxt" />&nbsp;
<button id="showBtn" >Click</button>
 </body>
</html>
<script type="text/javascript">
<!--
window.onload=function(){
    document.getElementById("showBtn" ).onclick=function(){
        var value=document.getElementById("decimalTxt" ).value;
        alert(toCurrency(value));
    };
};

function toCurrency(money) {  
   if (/[^0-9\.]/.test(money)){
        return '0.00';
    }

    money = money.replace(/^(\d*)$/, "$1.");
    money = (money + "00").replace(/(\d*\.\d\d)\d*/, "$1");
    money = money.replace(".", ",");
    var re = /(\d)(\d{3},)/;
    while (re.test(money)) {
        money = money.replace(re, "$1,$2");
    }
    money = money.replace(/,(\d\d)$/, ".$1");

    return '' + money.replace(/^\./, "0.");
}  
//-->
</script>
posted on 2013-02-18 16:30 何杨 阅读(1169) 评论(0)  编辑  收藏 所属分类: JavaScript

只有注册用户登录后才能发表评论。


网站导航: