0

I am consuming Dot net Web API which generates HighChart structure it has X and Y axis of type double.

The X-axis stores the DateTime EPOCH format for example (1554120000000), i am getting the correct format when i call the endpoint from postman

Expected number

But when i am consuming the same endpoint from my angular application, The number is getting converted to exponential (-1.7976931348623157e+308)

Parsed number

I have referred to the question! on Stackoverflow and used the method from the answer but it is not giving the correct number

var epochTime = 1554120000000;
var exponentialNumber = -1.7976931348623157e+308;

function toFixed(x) {
  if (Math.abs(x) < 1.0) {
    var e = parseInt(x.toString().split('e-')[1]);
    if (e) {
        x *= Math.pow(10,e-1);
        x = '0.' + (new Array(e)).join('0') + x.toString().substring(2);
    }
  } else {
    var e = parseInt(x.toString().split('+')[1]);
    if (e > 20) {
        e -= 20;
        x /= Math.pow(10,e);
        x += (new Array(e+1)).join('0');
    }
  }
  return x;
}
console.log("expected:" + epochTime)
console.log("result: " + toFixed(exponentialNumber));

How to avoid this converison, if not they how to parse the number correctly?

Roberto Zvjerković
  • 9,657
  • 4
  • 26
  • 47
  • https://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript Can you please refer this, it seems to be a known issue. – Alka Koul Apr 03 '19 at 06:37

2 Answers2

0

Just go through this - you might get to understand

https://playcode.io/281575?tabs=console&script.js&output

0

Can you refer this, may be you need to create your own custom method to read such numbers: How to avoid scientific notation for large numbers in JavaScript?

Alka Koul
  • 11
  • 2