I am taking number as input from user which could appox 100 digit . So how to use big Integer for online java script editor. i am giving 193619554647618082227851. what can we use for it.

var lines = input.split("\n")
for (var x = 0; x <= t; x++)
var num = Number(lines[x].split("\n"))

2 Answers

Nguyễn Ngọc Ẩn On

Number in javascript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent numbers between -(253 - 1) and 253 - 1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

If you want to appox 100 digit, you should be use string instead. You can use big.js for this case https://www.npmjs.com/package/big-js.

alexey28 On

The number is too long to be handled by javascript Number type. The solution might be to use https://www.npmjs.com/package/big-numbers. This library allow you to create big numbers (integer or floating point) from string. The code example:

const userNumber = numbers.of('193619554647618082227851');

One you create a number you can add, multiply, format and do any other arithmetic/logical operation.