I have a number generated as a finite decimal:
var x = k * Math.pow(10,p)
with k and p integers. Is there a simple way to convert it to an exact string representation?
If I use implict string conversion I get ugly results:
""+ 7*Math.pow(10,-1)
gives
"0.7000000000000001"
I tried using .toFixed and .toPrecision but it is very difficult to find the correct precision to use depending on k and p. Is there a way to get the good old "%g" formatting of C language? Maybe I should resort to an external library?