-2
var st = '{"total":2.47E-7}'
var b = JSON.parse(st);

How can I convert exponential value to decimal here using JS

  • `JSON.parse` does that, `2.47E-7` is a valid numeric literal. `b.total` will be the number. Did you try it and it didn't work? If so, how didn't it work? – T.J. Crowder Aug 07 '20 at 08:41
  • I tried it didn't work that's what I'm wondering – irkhaladkar Aug 07 '20 at 08:45
  • 1
    [It works just fine](https://jsfiddle.net/tjcrowder/oquv8jfw/). Note that when you output the number, it's output in standard form by default (which uses the exponent in this case). But it **is** a number. – T.J. Crowder Aug 07 '20 at 08:47
  • I mean to say it should be converted to 2.47 * 10-7 i.e 0.000000247 something like this – irkhaladkar Aug 07 '20 at 09:17
  • It's being converted to that number. It's just that when you output it, it's **shown** in e-notation. That's just how it's shown, though. – T.J. Crowder Aug 07 '20 at 09:37
  • but I want result in that format how can I do that? – irkhaladkar Aug 07 '20 at 09:38
  • See https://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript [Example](https://jsfiddle.net/tjcrowder/oquv8jfw/1/) – T.J. Crowder Aug 07 '20 at 09:40

1 Answers1

0

try this example

the result is itself if undefined comes

     var st = '{"total":2.47E-7}'
     var b = JSON.parse(st);
    
     console.log(b.total);
     var lastDigit = b.total.toString().split('-')[1] ;
          
     console.log(b.total.toFixed(parseInt(lastDigit) + 3))
dpmemcry
  • 117
  • 1
  • 4