Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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. -
BigInt is just a type for code which has to compensate for something.
TinyInts are the real deal! -
@AndSoWeCode the float number system doesn’t have good precision. Can’t even do 0.2+0.1 🤦♂️
-
@PonySlaystation bitcoin also uses big int. For tensorflow.js to work correctly, bigint should be a part of a bigger plan from Google 🤔
-
@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. 🤦♂️
-
@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.
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? 🤔
rant
javascript
v8
mozilla
firefox
chrome
bigint