Javascript之Number_format
来源:互联网 发布:t恤 知乎 编辑:程序博客网 时间:2024/05/28 23:13
// Formats a number with grouped thousands // * example 1: number_format(1234.56);// * returns 1: '1,235'// * example 2: number_format(1234.56, 2, ',', ' ');// * returns 2: '1 234,56'// * example 3: number_format(1234.5678, 2, '.', '');// * returns 3: '1234.57'// * example 4: number_format(67, 2, ',', '.'); // * returns 4: '67,00'// * example 5: number_format(1000);// * returns 5: '1,000'// * example 6: number_format(67.311, 2);// * returns 6: '67.31'// * example 7: number_format(1000.55, 1);// * returns 7: '1,000.6'// * example 8: number_format(67000, 5, ',', '.');// * returns 8: '67.000,00000'// * example 9: number_format(0.9, 0); // * returns 9: '1'// * example 10: number_format('1.20', 2);// * returns 10: '1.20'// * example 11: number_format('1.20', 4);// * returns 11: '1.2000' // * example 12: number_format('1.2000', 3);// * returns 12: '1.200'/** * number_format * * @param int or float number * @param int decimals * @param string dec_point * @param string thousands_sep * @return string */function number_format(number, decimals, dec_point, thousands_sep) { var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point, s = '', toFixedFix = function (n, prec) { var k = Math.pow(10, prec); return '' + Math.round(n * k) / k; }; // Fix for IE parseFloat(0.55).toFixed(0) = 0; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); if (s[0].length > 3) { s[0] = s[0].replace(//B(?=(?:/d{3})+(?!/d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec);}
- Javascript之Number_format
- JavaScript number_format function
- number_format
- 有意思的number_format
- PHP number_format()函数
- php内置函数number_format
- number_format()数据格式化
- 用number_format函数截取小数
- number_format需要注意的地方
- number_format 与 round 的区别
- 不使用number_format()函数格式化数字
- 关于number_format()的一些使用心得
- php中数字格式化函数number_format解析
- PHP number_format() 函数定义和用法
- php中number_format的学习使用
- 模仿php number_format函数的c# 价格转换函数
- ecshop number_format() 在php5.3以上的错误解决方案
- ecshop在php5.3以上的错误number_format() 解决方案
- 三层体系结构与数据库编程 .
- Ubuntu 10.04 LTS 安装 sun-java6-jdk 错误解决办法
- Android 对话框(Dialog)大全
- 数据库三层结构开发
- Android 之 下拉框(Spinner)的使用
- Javascript之Number_format
- Sqoop export and import commands
- ffmpeg开发指南
- zoj 2405 Specialized Four-Digit Numbers
- Report Categories修改LDB选择屏幕
- 如何解决iphone4 无法连接dlink无线路由器问题
- 一些有关C++语言中的bit操作
- 利用DevicePolicyManager执行屏幕锁定
- 如何用人