Weird division in js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Weird division in js

var x =67.2; x/=10; outputs 6.72000000001 how do I keep this from happening?

30th Oct 2021, 8:06 PM
ITDW
2 Answers
+ 3
I think u can use [.toFixed(n)] method to determine how many numbers will appear after . Note : write any number inside the method parantheses e.g var x = 67.2 x /= 10; z = x.toFixed(2) z = 6.72
30th Oct 2021, 8:17 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 1
The key word here is "floating point precision"
30th Oct 2021, 8:10 PM
Lisa
Lisa - avatar