+ 1

about float numbers in js?

When I changed the regular float number to float32, it decreased accuracy. why this happened?( line 47) although in the previous line, i've fixed its accuracy https://code.sololearn.com/WWK2BCo5v0Q9/?ref=app

29th Mar 2021, 12:17 PM
Mehran
Mehran - avatar
3 Answers
+ 3
29th Mar 2021, 5:34 PM
Zachiah sawyer
Zachiah sawyer - avatar
+ 1
Normal javascript numbers are very accurate and float32 arrays have less accuracy then normal js numbers. The point of typed arrays is for efficiency not accuracy.
29th Mar 2021, 2:29 PM
Zachiah sawyer
Zachiah sawyer - avatar
+ 1
Zachiah sawyer floating numbers in js behave like this:0.1+0.2=0.30000000000000004; we can use toFixed method to fix them. but when I assign it to float32, lose accuracy. why?
29th Mar 2021, 5:28 PM
Mehran
Mehran - avatar