mob
var
Dollars=0
verb
Add_Cash()
Dollars+=0.01
world<<"You now have $[Dollars]."
Problem description:
I am trying to get a dollar amount to show up in my game and it keeps failing by showing a lot more decimal places than there are numbers even, I used round() to round the number off properly but is BYOND not supposed to work with decimals because even the simple code above can't count to 1 without messing up.
It's telling me (You now have $0.839999.) And that's not even possible, so is BYOND meant to work with decimal values in the numbers or not?
I can also divide by 100 and use whole numbers as a solution, but then since BYOND's precision goes to 2^24 or 16,777,216 when adding 1 then my precision would affectively be 167,772.16
In hex, which is just compacted binary, 0.84 is 0.D70A3D70A3D70A3.... It repeats forever. Floating point can handle it rounded off to 0.D70A3D.
If you want to display dollars and cents--keeping in mind you will only have 6-9 digits of precision--then you'll have to multiply the number by 100 and round. But that too could introduce new rounding errors. For absolute full precision you'll need a lib that can handle bigger numbers, possibly storing them as strings.