joshy
New Member
- Messages
- 8
- Reaction score
- 0
- Points
- 0
I have been working on a calculation website for school. I have to divide numbers by 100 to convert from percentage to decimal. With some numbers, I get continuous decimal numbers, which by a normal calculator, doesn't happen.
Here's some examples (good and bad):
Also, if multiplied them by 10 (making 0.68 become 6.8 for example) then divided by 1000:
(Could be an issue with the '0')
I'm using JavaScript to code and Safari to view.
Any ideas, or should I try the multiply by 10 method?
EDIT: Have realised this is a common Javascript problem called a rounding error, and it's not just with 0's.
Here's some examples (good and bad):
Code:
0.13 / 100 = 0.0013 (good)
0.14 / 100 = 0.0014000000000000002 (bad)
0.141 / 100 = 0.0014099999999999998 (bad)
0.145 / 100 = 0.00145 (good)
0.67 / 100 = 0.0067 (good)
0.68 / 100 = 0.0068000000000000005 (bad)
Also, if multiplied them by 10 (making 0.68 become 6.8 for example) then divided by 1000:
Code:
0.68 * 10 = 6.8
6.8 / 1000 = 0.0068 (good)
0.141 * 10 = 1.41
1.41 / 1000 = 0.00141 (good)
I'm using JavaScript to code and Safari to view.
Any ideas, or should I try the multiply by 10 method?
EDIT: Have realised this is a common Javascript problem called a rounding error, and it's not just with 0's.
Last edited: