I'm trying to format numbers in Javascript using regex where the numbers are part of a formula. For example, given 12345.6789+9876.54321*-100
the result should be 12,345.6789+9,876.54321*-100
.
This is my attempt:
str.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")
and the result:
12345.6,789+9876.54,321*-100
It inserts commas in decimal places (PLUNK), how to fix this?