很多时候发现有时候js会提示自带函数不能使用,所以自己找了很多资料实现了个

html

<input type="text" class="input_text input_number" name="mgsy_dbnfjlr" value=""  onblur="this.value=fouces_qfh(this.value)" />

js函数

/**
* 自动补充百分比符号
* @param obj
* @returns {String}
*/
function fouces_bfh(obj) {
var o = obj.replace(',', '') + "";
if (o.indexOf("%") > -1) {
o = o.replace('%', '') + "";
//o = Number(o)/100;
}else{
o = o*100;
}
o = format1(o);
if (o.indexOf(".") <= -1) {
return o += ".00%";
}
if (o.substr(o.length - 1, 1) == ".") {
return o += ".00%";
}
if (o.substr(o.length - 2, 1) == ".") {
return o += "0%";
}
return o + "%";
}
/**
* 千分符格式化
* @param num
* @returns
*/
function format1 (num) {
if( num == null || num == undefined || num == "" ){
return "";
}
if( isNaN(num)) return num;
//alert(num);
//return (parseFloat(num).toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
return (toFixed(num,2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
} function toFixed(number, precision) {
var b = 1;
if (isNaN(number)) return number;
if (number < 0) b = -1;
var multiplier = Math.pow(10, precision);
return Math.round(Math.abs(number) * multiplier) / multiplier * b;
}

/**
* 千分符格式化
* @param num
* @returns
*/
function format1 (num) {
if( num == null || num == undefined || num == "" ){
return "";
}
if( isNaN(num)) return num;
//alert(num);
return (parseFloat(num).toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
//return (toFixed(num,2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
}

js-格式化数字保留两位小数-带千分符的更多相关文章

  1. JS格式化数字保留两位小数点示例代码

    格式化数字保留两位小数点实现的方法有很多,在接下来的文章中将为大家详细介绍下如何使用js来实现 a = a.toFixed(2);//保留2位但结果为一个String类型 a = parseFloat ...

  2. js中关于json常用的内容、js将数字保留两位小数

    没什么好说的  保存起来  以后有个地方找 var json=eval("[]") //json定义 var s={"id":"xxx",& ...

  3. js 格式化数字保留2位小数

    function toDecimal2(x) { var f = parseFloat(x); if (isNaN(f)) { return false; } var f = Math.round(x ...

  4. JS中格式化数据保留两位小数

    问题:在JS中格式化数据保留两位小数的函数的多种方法 最好方法: 保留两位好像是这样吧     var   a   =   9.39393;     alert(a.toFixed(2)); 说明: ...

  5. html模板中的数字保留两位小数

    <script> //html模板中的数字保留两位小数 function formatCurrency(num) { num = num.toString().replace(/\$|\, ...

  6. js设置百分比保留两位小数

      CreateTime--2017年8月23日11:03:31Author:Marydon js设置百分比保留两位小数 错误用法: var percent = (num1/num2) * 100%; ...

  7. easyui datagrid 格式化列显示两位小数、千分位

    { field: , formatter: function (value, row, index) { if (row != null) { ); } } }, //二位小数.千分位 { field ...

  8. JS 实现四舍五入保留两位小数并且添加千位分隔符

    var a = "-123456789.078";a = (Math.round(a * 100) / 100).toFixed(2).toString().replace(/(\ ...

  9. PHP数字价格格式化,保留两位小数

    number_format(($v['cash']/100),2); demo=>9,271.15

随机推荐

  1. Deploying an Internet Information Services-Hosted WCF Service

    Deploying an Internet Information Services-Hosted WCF Service .NET Framework 4   Other Versions .NET ...

  2. javascript高级程序设计 读书笔记1

    第二章  在HTML中使用JS 加载JS有三种:行内,head头部和外部链接JS   最好使用外部链接<script src="example.js" ></sc ...

  3. [No00005C]我也入住Markdown

    概览 宗旨 Markdown 的目标是实现「易读易写」. 可读性,无论如何,都是最重要的.一份使用 Markdown 格式撰写的文件应该可以直接以纯文本发布,并且看起来不会像是由许多标签或是格式指令所 ...

  4. curl命令

    定位后端接口是否ok,经常使用到curl -b/cookie  <name=string/file> cookie字符串或文件读取位置 curl http://localhost --co ...

  5. 利用scp 远程上传下载文件/文件夹和ssh远程执行命令

    利用scp传输文件 1.从服务器下载文件scp username@servername:/path/filename /tmp/local_destination例如scp codinglog@192 ...

  6. HTTP 错误 500.22 - Internal Server Error

    HTTP 错误 500.22 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设置. 最可能的原因: 此应用程序在 system.web/http ...

  7. 转 FileStream Read File

    FileStream Read File [C#] This example shows how to safely read file using FileStream in C#. To be s ...

  8. handlebars+require

    handlebars+require 最近在某网站看到了handlebars.js,出于好奇就百度了下这是神马玩意,结果让我很是欢喜,于是就开始自学下,handlebars就几个方法,蛮简单,言归正传 ...

  9. ThreadLocal原理及其实际应用

    前言 java猿在面试中,经常会被问到1个问题: java实现同步有哪几种方式? 大家一般都会回答使用synchronized, 那么还有其他方式吗? 答案是肯定的, 另外一种方式也就是本文要说的Th ...

  10. SQLServer(MSSQL)、MySQL、SQLite、Access相互迁移转换工具 DB2DB v1.2

    最近公司有一个项目,需要把原来的系统从 MSSQL 升迁到阿里云RDS(MySQL)上面.为便于测试,所以需要把原来系统的所有数据表以及测试数据转换到 MySQL 上面.在百度上找了很多方法,有通过微 ...