2
What type of variable can I use to generate as many decimals as possible in Javascript?
Ex.: 1.98719751097319284791284710237182479182471209381290481284
If possible, of course =)
2
What type of variable can I use to generate as many decimals as possible in Javascript?
Ex.: 1.98719751097319284791284710237182479182471209381290481284
If possible, of course =)
3
Javascript only has a numeric type, so it should use it. And of course, it has a maximum and it is this maximum that you can use.
It is good to know that JS uses a numerical type based on binary floating point and this means that there will be no numerical accuracy, if you need this does not give, but for the above it does not seem to be the case. The maximum is the Number.MAX_VALUE
.
console.log(Number.MAX_VALUE);
I put in the Github for future reference.
If this does not solve you will have to do or take a library that creates a type that meets your need.
1
Javascript numbers are always of the type Number
, and are always 64-bit floating point in the IEEE 754 standard:
The maximum value that can be reached is approximately 3.4028235 10e38
Browser other questions tagged javascript typing
You are not signed in. Login or sign up in order to post.
JS does not need to set a type for the variable just use
var
before, but inside she makes some kind of test to define the type for this variable?– Costamilam
This would be as high as possible or as many decimal places as possible?
– bfavaretto
@bfavaretto as it is in scientific notation whatever makes ;)
– Maniero
I tried to do the math to see if it beat, but I gave up in the middle rs. But I’ve been reading that the precision is around 15 digits, independent of the decimal point position. So it shouldn’t matter too much how many houses you can represent after that. I think. :)
– bfavaretto
@Guilhermecostamilam note that I have not spoken in variable, I have spoken in value, in dynamic typing languages the variables have no type, but the values always have. In these languages there is a tag together with the value then the variable has a type according to its value and this is tested internally to know what to do, including give error.
– Maniero
@bfavaretto is actually a little more complicated, as can be seen has more than 300 houses. This is not to say that all numbers can be represented, but it is possible to have that many houses. There are the most significant, in the case the representation showed 16 and "swallowed" 308.
– Maniero