1

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.

Vera Gavriel
  • 381
  • 2
  • 5
  • 14

1 Answers1

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