JSFiddle - React, Tailwind, and code Playground

by NickU

JavaScript

BigInt.To22_8 = function (decimalValue) {
    const parts = decimalValue.toString().split('.');
    let integerPart = BigInt(parts[0]);
    let decimalPart = BigInt(parts[1] ? parts[1].padEnd(8, '0') : '00000000');

    return (integerPart * BigInt(100000000)) + decimalPart;
};

BigInt.prototype.toString = function () {
    let str = this.toLocaleString('fullwide', { useGrouping: false });
    let length = str.length;
    if (length <= 8) {
        str = str.padStart(9, '0');
        length = 9;
    }
    return str.slice(0, length - 8) + '.' + str.slice(length - 8);
};

var a = BigInt.To22_8('12345678901234.00000001');
var b = BigInt.To22_8('0.00000001');
var c = a +b;




console.log(c.toString()); // --> 12345