Im using parseFloat on very high numbers or very low numbers. The return value is like 123*10e15 , I need to be like 123*10^15 . 15 needs to be in upper writing as a pow. Thanks.
Asked
Active
Viewed 431 times
1
-
Um, so what part of the conversion is giving you trouble? This seems like a straightforward textual substitution. – Raymond Chen Jul 17 '13 at 06:21
-
I think you mean `123e15`, **not** `123*19e15`. – Alvin Wong Jul 17 '13 at 06:21
-
`1230000000000000000` your desired output ? – rab Jul 17 '13 at 06:22
-
`parseFloat` parses `string` to floating point `number`. So the return value is `number`. `123*10e15` is `string` that represents `number`. – Mics Jul 17 '13 at 06:24
-
please look at Amadans answer and understand what i wanted. – Vera Gavriel Jul 17 '13 at 10:51
1 Answers
5
parseFloat
turns a string into a number. A number has no "format"; it gets turned back into a string (by Float
's method toString
) when you display it. If you want to display it with a caret, you will need to format (or reformat) it yourself into a string: easiest like this:
123e45.toString().replace('e', '*10^') // result: "1.23*10^+47"
(if the +
bugs you, you can try this, using a regexp:)
123e-45.toString().replace(/e\+?/, '*10^') // result: "1.23*10^47"

Amadan
- 191,408
- 23
- 240
- 301
-
good, that solves the replacement , now..how can i make the 45 an upper text like pow? – Vera Gavriel Jul 17 '13 at 10:49
-
Are you now talking about HTML? `.replace(/e([+-]?\d+)/, '*10$1')`. If you're not talking about HTML, then you probably can't. – Amadan Jul 17 '13 at 13:40