I\'ve got a currency input and need to return only significant digits. The input always has two decimal places, so:
4.00 -> 4
4.10 -> 4.1
4.01 ->
Your code also chops off zeros in numbers like "1000". A better variant would be to only chop of zeros that are after a decimal point. The basic replacement with regular expressions would look like this:
str.replace(/(\.[0-9]*?)0+$/, "$1"); // remove trailing zeros
str.replace(/\.$/, ""); // remove trailing dot