Why is JS math wierd? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is JS math wierd?

just look at this: https://code.sololearn.com/WQv56rsKmWT6/?ref=app

18th Jan 2018, 10:26 PM
Ojani
Ojani - avatar
7 Answers
+ 10
@Johnathan. JS is fine at math. It is the floating point data type that is the problem here. Excerpt from the article you linked: It's interesting that this behavior is often attributed to JavaScript, while it’s pertaining to any language the uses floating point format for numbers. This means that if you use ‘float’ or ‘double’ data types in Java or C you’ll see the same result.
19th Jan 2018, 12:35 AM
jay
jay - avatar
+ 5
idk this is really wierd , hope someone answer this question
18th Jan 2018, 10:40 PM
Maher Zaidoune
Maher Zaidoune - avatar
+ 4
@jay, I do understand your point. But when it comes to precision calculations, JavaScript is not the best one. But there's hope based on @Ace's post.
19th Jan 2018, 12:42 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 4
@Ojani: yes
19th Jan 2018, 11:14 AM
jay
jay - avatar
+ 2
JavaScript is not really good at math. 0.1 + 0.2 !== 0.3. It has only one number type which causes that error unlike other languages. That issue gave me a headache before. https://medium.com/dailyjs/javascripts-number-type-8d59199db1b6
19th Jan 2018, 12:00 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
I was thinking on making a calculator with JS and html. Should go for it anyways?
19th Jan 2018, 11:09 AM
Ojani
Ojani - avatar