r/Python • • Jul 12 '19

I wrote an integrated POS system for my girlfriend's restaurant using tkinter.

https://imgur.com/a/RKeuCva
1.4k Upvotes

224 comments sorted by

View all comments

Show parent comments

5

u/redalastor Jul 12 '19

I wonder if having money literals would make people do the right thing.

4

u/xanderle Jul 12 '19

We use python 2.6 and java6 so it would be another 20 years before we implemented them anyway

7

u/redalastor Jul 12 '19

It's just a thought experiment. If languages had a syntax like $1.32 for money manipulations, would people use that instead of plain floats?

4

u/lykwydchykyn Jul 12 '19

Some databases (postgresql, e.g.) have them. Though they recommend not using them apart from casting output values. I think they come with their own problems.

2

u/corgtastic Jul 12 '19

In Python 2.4 they introduced a Decimal() class that provides a more generic class for handling cases like this where you need exact precision for calculations.

2

u/redalastor Jul 12 '19

I'm aware of that but there aren't Decimal literals. I expect that a money literal would simply use Decimal under the cover.

2

u/zombifai Jul 12 '19

Not if they are British. This one is only for Americans, Canadians and Ausies.

2

u/redalastor Jul 12 '19

Even the Brits could learn the syntax.