因此,我们必须在>后面进行一些手动逗号插入添加逗号或空格以每三位数分组一次: var n = 123456.789;var str = n.toFixed(2).replace(/(\ d)(?=(\ d {3})+ \.)/g,'$ 1,'); 其中 str 现在是 123,456.79 .I need to display the numbers with comma separated like 120,456.02I tried the below method using js and it worked fine. But in apps scripts, it throws illegal radix exceptionfunction toDec(n) { //return parseFloat(Math.round(n * 100) / 100).toFixed(2) + ' '; will display without comma return Number(parseFloat(Math.round(n * 100) / 100)).toLocaleString('en-US', {minimumFractionDigits: 2});}Any workaround available? 解决方案 In GAS toLocaleString is just an alias for toString, and is therefore useless. (Relevant bug tracker item from Rhino, on which GAS runs.)So, we have to do some manual comma insertion following Add commas or spaces to group every three digits:var n = 123456.789;var str = n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');where str is now 123,456.79. 这篇关于在GAS中使用语言环境字符串方法显示逗号分隔的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 22:05