javascript 格式化货币编号

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 格式化货币编号相关的知识,希望对你有一定的参考价值。

/**
 * Format currency number
 * @param currency {number} the amount you need to format
 * @param separate {string} separator between units, default .
 */
function formatCurrency(currency, separate = "."){ 
    var s = currency.toString(); 
	var regex = /\B(?=(\d{3})+(?!\d))/g; 
	var ret = s.replace(regex, separate); 
	return ret;
}

// Usage
console.log(formatCurrency(10000))

以上是关于javascript 格式化货币编号的主要内容,如果未能解决你的问题,请参考以下文章