From a datasource I'm getting many numbers that need formatting before presenting in a browser.
Some of the numbers appear with trailing zeros, and some of the numbers appear with a trailing decimal point with nothing afterwards.
Here are examples of what I've been trying to achieve with Javascript's RegEx implementation:
130.0000 = 130
132.0050 = 132.005
16.9000 = 16.9
140000000.00 = 140000000
132. = 132
89.0 = 89
90.0 = 90
9000.00 = 9000
99.0 = 99
99.00500 = 99.005
70 = 70 //fail, as it matches the zeros at the end if there's no decimal point
700 = 700 //fail, as it matches the zeros at the end if there's no decimal point
The following RegEx matches everything correctly except the last two tests where any zeros before the decimal point are also matched:
[\.0]0*$
Any help with what's now giving me a headache would be greatly appreciated.
Many thanks in advance...