Have I missed a standard API call that removes trailing insignificant zeros from a number?
Ex.
var x = 1.234000 // to become 1.234;
var y = 1.234001; // stays 1.234001
Number.toFixed() and Number.toPrecision() are not quite what I'm looking for.
How about just multiplying by one like this?
If you cannot use Floats for any reason (like money-floats involved) and are already starting from a string representing a correct number, you could find this solution handy. It converts a string representing a number to a string representing number w/out trailing zeroes.
Strip trailing zeros easy way with big.js Just simple trick
1.234000 => 1.234
None of these solutions worked for me for very small numbers. http://numeraljs.com/ solved this for me.
I needed to solve this problem too when Django was displaying Decimal type values in a text field. E.g. when '1' was the value. It would show '1.00000000'. If '1.23' was the value, it would show '1.23000000' (In the case of a 'decimal_places' setting of 8)
Using parseFloat was not an option for me since it is possible it does not return the exact same value. toFixed was not an option since I did not want to round anything, so I created a function:
Here's a possible solution: