JFC please don't use floating point types for calculating financial transactions or storing monetary values. I just got asked to review some code by someone and it is the first thing I spotted.
[#]roundingerrors #floatingpoint #softwareengineering
=> More informations about this toot | More toots from kelpana@mastodon.ie
@kelpana @becomethewaifu Having never done banking, I wonder what monetary unit they use for their basic integer values.
It'd need to handle conversion between USD and hyperinflated currencies, after all.
=> More informations about this toot | More toots from lispi314@udongein.xyz
@lispi314 @kelpana @becomethewaifu haven't worked at a bank but on a team that handles transactions and we rely on the USD penny as the unit.
=> More informations about this toot | More toots from jeremiah@tldr.nettime.org
@jeremiah @becomethewaifu @kelpana Wouldn't that start to have precision problems the minute something even as mundane as the Yen gets involved?
Though I suppose if the company only does business in USA then it's irrelevant.
=> More informations about this toot | More toots from lispi314@udongein.xyz
@lispi314 @kelpana @becomethewaifu @jeremiah
Java BigDecimal can handle it all, precisely, regardless of scale.
But do realize that currency conversion factors are barely good to two decimal places, on a good day.
Rounding is always a critically important business issue.
And so is accumulating currencies for batch conversion to avoid loss.
There are "banker's rounding" tricks (that predate computers) to ensure that the totals, when computed independently, add up exactly.
=> More informations about this toot | More toots from JeffGrigg@mastodon.social
@JeffGrigg @jeremiah @becomethewaifu @kelpana So ultimately, rounding errors past a certain point are considered acceptable.
And yeah, proper arbitrary precision reals/decimals/rationals libraries are an option, though I thought that maybe they didn't use them due to the performance peculiarities they tend to involve.
=> More informations about this toot | More toots from lispi314@udongein.xyz
@lispi314 @kelpana @becomethewaifu @jeremiah
Java BigDecimal is essentially BigInteger with logic to keep track of decimal places. Exactly. To any number of decimal places that will fit in memory.
Like more than needed to track the number of particles in the universe. I've had it out over 200 places to the right of the decimal, computed exactly.
But then you must apply business logic to round to something sane, like pennies. The rounding will also be exact. Like exactly half a cent.
=> More informations about this toot | More toots from JeffGrigg@mastodon.social
@JeffGrigg @jeremiah @becomethewaifu @kelpana > Like more than needed to track the number of particles in the universe. I've had it out over 200 places to the right of the decimal, computed exactly.
Ah good, so it is the Java equivalent of those libraries I was familiar with.
=> More informations about this toot | More toots from lispi314@udongein.xyz This content has been proxied by September (3851b).Proxy Information
text/gemini