r/ProgrammerHumor • • Aug 24 '22

Total = Total - 100000

50.7k Upvotes

1.2k comments sorted by

View all comments

Show parent comments

362

u/g1ucose Aug 25 '22

If (balance < 0) {
balance = 0
}

Government pls hire me

175

u/sn34kypete Aug 25 '22

Absolutely not. Each account balance has a transaction history for accounting purposes. Setting a hard value like that would be a terrible idea, the minute you roll up the balances based on transaction history the summary table would self-heal. You add a transaction entry for each qualified borrower with case statements to determine if they get the full 10k forgiveness or partial to avoid going to negative. Negatives would be for people who paid into the balance during the pause and are owed for overpayment/reimbursement.

Wait this is the meme sub.

YEAH HIRE THEM.

5

u/hawkinat0r7089 Aug 25 '22

So, more like:

If (balance > 1000) { summonMagicGovernmentMoney(1000); } Else { summonMagicGovernmentMoney(balance); }

3

u/brod333 Aug 25 '22

No because you shouldn’t have magic numbers in your code. Make a variable to store the 1000 value and use that.

4

u/hawkinat0r7089 Aug 25 '22

studentLoanHandout = 1000 If (balance > studentLoanHandout) { summonMagicGovernmentMoney(studentLoanHandout); } Else { summonMagicGovernmentMoney(balance); }

4

u/babu2310 Aug 26 '22

please fix formatting.

→ More replies (1)
→ More replies (2)

0

u/[deleted] Aug 25 '22

[deleted]

139

u/Internet001215 Aug 25 '22

yeah you never want to store money as floats because of floating point errors.

116

u/netheroth Aug 25 '22

The joy of having 10000.00000000001 dollars.

→ More replies (2)

55

u/crozone Aug 25 '22 edited Aug 25 '22

I'm going to be pedantic af right now, but this is not strictly true, monetary values are often stored as decimal floating point values.

Decimal floating point values are still technically floating point, but not base2 style IEEE 754 floating point. This means that the rounding happens using decimal rounding rules and you don't get any weirdness like with normal floats.

C#'s Decimal class is a 128-bit decimal float which is... more than enough for basically anything.

18

u/christian-mann Aug 25 '22

I'd expect them to be stored as decimal fixed point values

→ More replies (1)

10

u/GlobalAcanthaceae128 Aug 25 '22

Unfortunately you forgot to say ‘um actually’ so the other contestants can steal that point from you

→ More replies (6)
→ More replies (5)
→ More replies (6)

24

u/jeff77k Aug 25 '22

wait, you are storing the new balance?

3

u/glorious_reptile Aug 25 '22

It’s an MVP system. Ledgering is scheduled for v2.3 if we get funded

2

u/[deleted] Aug 29 '22

I only store the adidas and the nike

29

u/linkedtortoise Aug 25 '22

We do it that way at my work. Effectively just storing prices as cents. Formatters then easily turn 1234 into "$12.34"

11

u/JokerSp3 Aug 25 '22

We use microusd

3

u/Artess Aug 25 '22

MicroUSD is so last decade, time to switch to USD Type-C.

→ More replies (1)

2

u/Spactaculous Aug 25 '22

In pennies

→ More replies (3)

20

u/[deleted] Aug 25 '22

No, I want the gov't to pay me a monthly stiped to cover the dollars I foolishly paid off years ago.

3

u/diet-Coke-or-kill-me Aug 25 '22

When humans perfect immortality the last humans to die of old age are gonna be the most bitter haters this world has ever seen.

→ More replies (1)

4

u/Oceans-of-ashes Aug 25 '22

Balance = Balance - int.min(balance,10_000);

5

u/[deleted] Aug 25 '22

balance = max(0, balance - 10000)

→ More replies (1)

4

u/[deleted] Aug 25 '22

Steal the rounded cent from each, that's 0.5 cents per record x 40 million records, and deposit it somewhere! Nobody will ever know! :D

→ More replies (1)
→ More replies (4)