Here\'s the scenario: I\'m getting .9999999999999999 when I should be getting 1.0.
I can afford to lose a decimal place of precision, so I\'m u
None of these really got me what I was looking for based on the question title, which was, for example, for 5.00 to be 5 and 5.10 to be 5.1. My solution was as follows:
num.toFixed(places).replace(/\.?0+$/, '')
'5.00'.replace(/\.?0+$/, '') // 5
'5.10'.replace(/\.?0+$/, '') // 5.1
'5.0000001'.replace(/\.?0+$/, '') // 5.0000001
'5.0001000'.replace(/\.?0+$/, '') // 5.0001
Note: The regex only works if places > 0
P.S. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed