0

we have string input number input="6145390195186705543" if we want to convert to number ;java Script auto rounded this input;

(6145390195186705543)

(6145390195186705000)

  • 4
    `BigInt(input)` https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/BigInt – evolutionxbox Nov 04 '22 at 10:31
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) (among others) – evolutionxbox Nov 04 '22 at 10:31

1 Answers1

0

This should work for what you are trying to achieve

const myFunction = (num) => {

const length = num.length;

const result = `(${num.slice(0,16).padEnd(length, "0")})`;
return result;
};

const input="6145390195186705543";
const output = myFunction(input); 
console.log(output)
otejiri
  • 1,017
  • 6
  • 20