可以通过缩放来进行分到元的转换,同时使用正则对处理后的数字进行千分位格式化

方法1:(不丢失精度)


function Fen2Yuan( num ) {
if ( typeof num !== "number" || isNaN( num ) ) return null;
return ( num / 100 ).toFixed( 2 );
}

方法2:


var num = 370825
num=num*0.01;//分到元
num+='';//转成字符串
var reg=num.indexOf('.') >-1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;//千分符的正则
num=num.replace(reg, '$1,');//千分位格式化

最终 num = 3,708.25

经过上述4步,即可完成分到元的转换,并且有千分位的格式化

正则 js分转元带千分符号的更多相关文章

  1. JS 正则中环视(断言)应用 -- 数字千分符

    介绍一下顺序环视 (?=...) 和逆序环视 (?<=...) 方便不想看长文的人,如果在支持 ES2018 的环境中整数可以这样使用: String(12345678).replace(/(? ...

  2. js-格式化数字保留两位小数-带千分符

    很多时候发现有时候js会提示自带函数不能使用,所以自己找了很多资料实现了个 html <input type="text" class="input_text in ...

  3. 在SQL service或Oracle中将数字转换成有千位符号

    1.在SQL service中的写法: --Function主体 CREATE FUNCTION [dbo].[FnMoneyStyle](@Number )) RETURNS VARCHAR() A ...

  4. javascript中将整数添加千位符号

    如果num是整数的话,将其转换成带千位符号的字符串: Number(num).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' +  ','); 另 ...

  5. JavaScript千分符---正则实现

    一般在JavaScript中实现千分符,是使用切割+连接一顿操作 这里尝试一下使用正则快速实现千分符 let num0 = '12' let num1 = '123' let num2 = '1234 ...

  6. js解决千分符问题

    js脚本function: //js数字千分符处理 function commafy(num) { num = num + ""; var re = /(-?\d+)(\d{3}) ...

  7. js解决千分符问题[收藏下]

    //js数字千分符处理 function commafy(num) { num = num + ""; var re = /(-?\d+)(\d{3})/ while (re.te ...

  8. JS数字千分

    JS数字千分: 1.例子:1000--->1,000 2.实现如下: salesToFormat: function (num) { var num = (num || 0).toString( ...

  9. js 获取当天23点59分59秒 时间戳 (最简单的方法)

    js 获取当天23点59分59秒 时间戳 (最简单的方法) new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60* ...

随机推荐

  1. POJ 1469 COURSES 二分图最大匹配 二分图

    http://poj.org/problem?id=1469 这道题我绝壁写过但是以前没有mark过二分图最大匹配的代码mark一下. 匈牙利 O(mn) #include<cstdio> ...

  2. bzoj 2406 二分+有源有汇上下界网络流可行流判定

    弱爆了,典型的行列建模方式,居然想不到,题做少了,总结少了...... 二分答案mid s----------------------->i行-----------------------> ...

  3. How to exit the entire application from a Python thread?

    If all your threads except the main ones are daemons, the best approach is generally thread.interrup ...

  4. HDU 4709 Herding (枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. Tasker to proximity screen off

    If you are using proximity screen off pro or smart screen off, you may know how convenient it is to ...

  6. Namespace declaration statement has to be the very first statement in the script

    php 中 Namespace declaration statement has to be the very first statement in the script 错误解决方法: 在PHP文 ...

  7. VS2010下配置Winpcap 开发环境

    http://blog.csdn.net/taotaoyouarebaby/article/details/27326829

  8. STM32学习笔记3-IO配置输入输出

    STM32的IO配置时没什么特殊的,有个注意点就是有用IO前须要先打开其时钟线,下面是验证过oK的程序: RCC->APB2ENR|=GpioBApb2enrEn; //使能PORTB时钟 GP ...

  9. Java: 复制文件最快方法

    利用Java复制文件到处都可以用到,这里总结了一个类供大家参考.里面总共有两个方法: public static boolean copyFile(String srcFileName, String ...

  10. [翻译] 学习iOS开发的建议:如何从菜鸟到专家

    [文章原地址] http://mobile.tutsplus.com/tutorials/iphone/ios-quick-tip-from-novice-to-expert/ 翻译有误之处请勿见笑, ...