I would love to be able to move a decimal point 2 places across an unknown amount of numbers without using math. I know that seems weird, but finite precision causes some shifts. My javascript is not strong, but I’d really like to learn how to chop up a number and do this if it’s possible. So, I’m hoping you awesome folks can help.
The problem:
- 575/960 = 0.5989583333333334 using the console
- I would like to make that a copy and pastable percentage like: 59.89583333333334%
- If I use math and multiply by 100, it returns 59.895833333333336 because of finite precision
Is there a way to make that a string and just always move the decimal 2 places to the right to skip the math?
Here’s a fiddle too, with the codes: http://jsfiddle.net/dandenney/W9fXz/
If you want to know why I need it and want the precision, it’s for this little tool that I made for getting responsive percentages without using the calculator: http://responsv.com/flexible-math
If the original number is of this type of known structure and always has at least two digits to the right of the decimal, you can do it like this:
Working demo with test cases: http://jsfiddle.net/jfriend00/ZRNuw/