BigInt (BG08)
1: function numberToBigInt(numberValue) {
2: if (typeof numberValue !== 'number' || !Number.isInteger(numberValue)) {
3: throw new TypeError('Input must be an integer Number');
4: }
5: return BigInt(numberValue);
6: }
7:
8: // Example usage:
9: const numberValue = 1234567890123456789;
10: const bigIntValue = numberToBigInt(numberValue);
11: console.log(bigIntValue); // 1234567890123456789n
Convert Number to BigInt - The Number must be an integer; otherwise, it will throw an error. 1234567890123456768n
BigInt context:
ES6 context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/JavascriptES6/BG08.htm
|
|