I'm trying to truncate some longitude coordinates without any rounding issues. I thought replace() would be the simplest way to do this.
My regex is correct, but I'm apparently not using replace correctly.
Here's my stripped down example. I need to strip all decimal points after the 8th position
var truncRegex = /-?\d+?\.\d{8}/;
console.log('-81.82297519999997'.replace(truncRegex, '$1'));
What's happening is replace() is stripping the match and leaving me with the remainder prepended with "$1". The result is: $1999997
Number("...").toFixed(8)