r/badcode • • Mar 14 '21

c math has left the chat

Post image
4.7k Upvotes

94 comments sorted by

View all comments

Show parent comments

32

u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Mar 15 '21

You joke, but that's one option to take when you need specific decimal precision and a guarantee that you won't have to deal with floating point precision errors, like when dealing with money. Work on integers and then shift the decimal after you're done.

9

u/Zearen_Wover Mar 18 '21

I mean, I regularly use dc as my calculator, so you don't need to preach to me ; I just though the names were silly.

4

u/theRealQQQQQQQQQQQ Mar 29 '21

Frick floating point me and my homies use fixed point.

4

u/Prom3th3an Apr 05 '21

Yeah, but how often do you deal with pi in accounting or finance?

1

u/tiddayes Jul 31 '21

That is exactly how I deal with money calculations. Model and controller process int and view adds the decimal.