5

Just saw BigInt in chrome 67. Seems very useful in currency calculations. Searched on Mozilla, found nothing. Is it a V8 only thing, or another browser will catch up soon? Anyone have any idea? 🤔

Comments
  • 4
    What's wrong with regular Number?
    It keeps its precision up to 2^53. You can safely store currencies (in cents) up to millions, which should be enough unless you live in Zimbabwe.

    Edit: But if you're in Zimbabwe, you don't care about cents, or thousands, or even millions, so it's fine. Just do the cut-off at the billions and count the quintillions.
  • 1
    BigInt is just a type for code which has to compensate for something.
    TinyInts are the real deal!
  • 0
    @AndSoWeCode the float number system doesn’t have good precision. Can’t even do 0.2+0.1 🤦‍♂️
  • 2
    @PonySlaystation bitcoin also uses big int. For tensorflow.js to work correctly, bigint should be a part of a bigger plan from Google 🤔
  • 1
    @sunfishcc it was just meant as a joke 😉
  • 0
    @irene yeah, it’s pain in the ass. Classic js interview problem. But we actually having trouble when calculating plastic bigs, stickers for fruits etc. so the client side value often don’t exactly match the report from db. 🤦‍♂️
  • 2
    @PonySlaystation I give you my AI cat face😼
  • 2
    @sunfishcc yes, but 1+2 will always yield 3 in JS.

    The trick is to get rid of the decimals part, so don't deal with dollars, deal with cents. Or if you want more precision, go for stuff like "millis" or "micros".

    Basically $31.57 becomes 3157, or 31570 if you want more precision. There is only conversion on input and output, but inside it's all handled in these units. Unless you go for really big numbers, you're fine.
  • 0
    @AndSoWeCode true, always use the lowest viable nominator
Add Comment