views:

52

answers:

2

hey there!

sorry, but i'm not that maths guy, so i do not know how it is really called:

number 12345678901234567890123 could be also stated as 1.2345678901234567890123 * 10^22 (if i'm right and did not miss any decimal...)

consider this javascript:

var number = 12345678901234567890123;
var stringValue = number.toString();

if i do so, it renders the alternative translation (mentioned above). instead i want to render simple, plain, ... 12345678901234567890123

how can this be done?

EDIT:
just to be clear: the number i want to render, does not contain any decimal places. it's just a simple 12345678901234567890123 ... not 12345678901234567890123.123 or anything likewise. and, as i'm with javascript, typeof is number

+1  A: 

yes, I understood. It's just that if in this case Javascript uses float as an internal type to store this number, approximation already takes place, and your integer very large number is transformed to an approximated value in float or double. Double may still have a high accuracy, but in float I can guarantee that you would lose or gain a few billions. Though you are storing 10^22 large number. Don't expect accuracy, not even from double. I can assure you that if JS has represented your number to 1.23445E+22, then you've got a serious approximation.

– Alexander

Andreas Niedermair
+1  A: 

if you still want to deal with numbers on the order of 10^22 without rounding, then you should use a BigInt class, which implements arbitrary sized numbers. There are several BigInt javascript implementations you can find on the net.

Lie Ryan