Integer Values That Are Actually Readable // Python Tips

preview_player
Показать описание


#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

This is useful to separated 100s but to indicate decimal replacement as in this particular, makes it a bit contextual. What I mean is, you will have to store somewhere the information(only for the reader of course) that the underscore before the last two digit place suggests decimal separation.

terrifictitash
Автор

Every time I watch your videos I feel I become a bit smarter. What a way to make an impact on the world. Thanks.

bckzilla
Автор

Keep up with these shorts. Very informative.

herressy
Автор

I was weirded out at first, then amazed. Never thought about doing it that way.

re.liable
Автор

I love this, and I do the same.

Also, storing money amounts in integer cents is VERY useful. I can't count how many times I've seen coders (even very experienced coders) use floats to store money ($$$.cc). Bad idea, because of the way floats are stored in binary. For example, If you add 1.01 and 1.02, you don't get 2.03; you get which can raise havoc, when you're trying balance the sum of your invoice lines to the amount paid. Just store the amounts as integers and insert the decimal point (divide by 100) only when you print or display.

Some languages (MySQL and Postgres SQL, for example) support a NUMERIC or DECIMAL data type, which is simply an integer with an implied decimal point, avoiding the floating point problem and eliminating the need to remember where the decimal point goes.

kenhaley
Автор

Why didn’t I know this? Your content is insanely high quality. I’ve learned such a lot!

_indrid_cold_
Автор

Wow, I actually had no idea you could do this. I love all your tips but this one seems like it could be potentially confusing or a time sink. I suppose if you are really trying to avoid expressing the value as a float it might make things easier to read in some niche cases? Good video regardless, not many would know this.

rorydenham
Автор

Excellent, especially large Numbers such as billions are more clearly written in this format.

mabml
Автор

could you please suggest some books or resources for python?

geeksbyte
Автор

wow that's interesting, didn't know you could do that.

TheFootballPlaya
Автор

This is pretty cool, I had no idea. It's also interesting that I can buy a Tesla for the price of 4000 salads.

ran_red
Автор

Uhhh, if I saw this, I would be hugely confused. I know I can put underscores but all I have ever saw or think in my mind was to use it for thousands. 1000 -> 1_000. Not for abstract numbers as this is. Anyway, I love your content :-) Just my 2c

songokussjcz
Автор

Why not just use the Decimal type instead? That’s what it’s for:

from decimal import \
Decimal as D

PRICES = \
{
"burger" : D("10.00"),
"fries" : D("5.00"),
"drink" : D("2.00"),
"salad" : D("15.00"),
}

lawrencedoliveiro
Автор

If you buy a burger along with a Tesla you are Joe No.2_000
But if you buy a Tesla with your burger you are Elon Musk ! 😎😎

oreychandan
Автор

I don't think it makes much sense to have the prices in cents.
I would have them in dollars, then use fp numbers, and instead of 'prices', I would call it prices_in_dollars, so people reading the code know straight what unit we are using.

jimmorrison