I need to display the numbers with comma separated like 120,456.02
I tried the below method using js and it worked fine. But in apps scripts, it throws illegal radix exception
function 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 fortoString
, 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:
where
str
is now123,456.79
.