V
V
Vazgen Aleksanyan2019-02-11 15:19:45
JavaScript
Vazgen Aleksanyan, 2019-02-11 15:19:45

How to get a number without letter e?

There is a + b = 712577413488402631964821329 but in the browser the result is 7.125774134884027e+26;
Maybe there is such a method in javascript that will make this number normal - 712577413488402631964821329 ??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zendor, 2019-02-11
@VazgXa

For example like this (my code once solved a similar problem on codewars ):

Decision
function sumStrings(s1, s2) {
  if (s1.length < s2.length) [s1, s2] = [s2, s1];
  s1 = [...s1].reduceRight((a, c, i) => {
    c = +c + ~~s2[i - (s1.length - s2.length)] + a.r;
    a.s = c % 10 + a.s;
    a.r = c / 10 | 0;
    return a;
  }, {r: 0, s: ''});
  return ((s1.r || '') + s1.s).replace(/^0+(?=\d)/, '');
}

S
Stalker_RED, 2019-02-11
@Stalker_RED

Number.MAX_SAFE_INTEGER
9007199254740991

Your 712577413488402631964821329 is much larger than MAX_SAFE_INTEGER
Therefore, such operations cannot be carried out "on the forehead".
You can use some library that implements long arithmetic .
Or write your own.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question