六月 14, 2019

如何使用JavaScript正規表示式顯示數值千分位

JavaScript如何使用正規表示式顯示數值千分位

n = "1279834847944074100465236.33";
re = /(d{1,3})(?=(d{3})+(?:$|D))/g ;
n1 = n.replace(re,"$1,");

console.log(n + "

" + n1);

Demo


© UCAMC. All rights reserved.
Powered by CITIAR.