View Full Version : Exponent to number

varalakshmi

11-05-2012, 07:48 PM

How to convert an exponential value to numeric value using java script

Ex:

1.700000000000001e+308 converted to be its numeric value.

Can anyone please help me to achieve this using jquery/java script?

Philip M

11-05-2012, 08:16 PM

How to convert an exponential value to numeric value using java script

Ex:

1.700000000000001e+308 converted to be its numeric value.

Can anyone please help me to achieve this using jquery/java script?

<script type = "text/javascript">

var x = (1.23e+20).toFixed(6); // Returns "123000000000000000000.000000" - note added zeroes

alert (x);

var y = (1.23e-10).toFixed(2); // Returns "0.00"

alert (y);

</script>

1.700000000000001e+308 is too large a number for Javascript to handle.

It is not as cold as it was yesterday, but that's probably because it's a bit warmer. - BBC Scotland News.

Old Pedant

11-05-2012, 08:31 PM

1.700000000000001e+308 is too large a number for Javascript to handle.

Ummm...actually, the largest number JS can handle is a tad larger than that.

1.7976931348623157 e +308

I *think* what Philip means is that JS can't convert a number that large to NON-scientific notation.

If it were converted, it would be 309 digits long. No human could make sense of it, so the scientific notation is much better for this purpose.

I only tested on Chrome, but the largest exponent JS will convert to fixed notation in Chrome is e+20. After that, it reverts to always using scientific notation.

Philip M

11-05-2012, 11:52 PM

Ummm...actually, the largest number JS can handle is a tad larger than that.

1.7976931348623157 e +308

I *think* what Philip means is that JS can't convert a number that large to NON-scientific notation.

If it were converted, it would be 309 digits long. No human could make sense of it, so the scientific notation is much better for this purpose.

I only tested on Chrome, but the largest exponent JS will convert to fixed notation in Chrome is e+20. After that, it reverts to always using scientific notation.

Yes, that was what I intended to convey. The number is too big to be displayed other than in scientific notation.

felgall

11-06-2012, 09:58 PM

I'd start by using parseFloat to convert thoose strings to numbers - as that's what parseFloat is for.

If you did that then numbers too big for JavaScript to handle would report as infinity rather than as zero.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.