Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does JavaScript use base 10 floating point numbers (according to w3schools)?

Tags:

javascript

I read this on W3Schools:

All numbers in JavaScript are stored as 64-bit (8-bytes) base 10, floating point numbers.

This sounds quite strange. Now, it's either wrong or there should be a good reason not to use base 2 like the IEEE standard.

I tried to find a real JavaScript definition, but I couldn't find any. Either on the V8 or WebKit documentation, the two JavaScript implementation I could find on Wikipedia that sounded the most familiar to me, I could find how they stored the JavaScript Number type.

So, does JavaScript use base 10? If so, why? The only reason I could come up with was that maybe using base 10 has an advantage when you want to be able to accurately store integers as well as floating point numbers, but I don't know how using base 10 would have an advantage for that myself.

like image 936
Steven Roose Avatar asked Jan 26 '13 18:01

Steven Roose


1 Answers

That's not the World Wide Web Consortium (W3C), that's w3schools, a website that isn't any authority for any web standards.

Numbers in Javascript are double precision floating point numbers, following the IEEE standards.

The site got the part about every number is a 64-bit floating point number right. The base 10 has nothing with the numerical representation to do, that probably comes from the fact that floating point numbers are always parsed and formatted using base 10.

like image 172
Guffa Avatar answered Sep 22 '22 02:09

Guffa