Python Can't Do Math?? #python #programming #coding

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

Background Music:
Creative Commons Attribution-ShareAlike 3.0 Unported
Рекомендации по теме
Комментарии
Автор

This happens in any language that uses floating point math.

alesandreo
Автор

fun fact: you don't use floats or double for currencies. you use int and long

FuDaVan
Автор

** proceeds to check this information in repl **

alejandroangongandara
Автор

Thats why python has Fraction(). I was so surprised to know this, it basically represents all rational numbers with no information lost by dividing.
You can do all kinds of operations with it too, and you get back a fraction.
Its all fine until you have to convert floats to fraction lol

John
Автор

Quickly. Floating points use binary addition which is fractional addition so 0.7 and 0.6 are represented in memory as binary numbers which add differently compared to base-10 numbers.

andrewhabroad
Автор

If you do actual scientific calculations that make sense to use floating-point over decimals, the math.isclose() function is useful to dodge rounding problems. 0.6 + 0.7 != 1.3, but isclose(0.6 + 0.7, 1.3) is true even if you lower the "relative tolerance" parameter from 10^-9 to 10^-15.

DSamp
Автор

"Insufficient funds" command and conquer players will understand

Zend
Автор

Ok my mind is blown, we just learned about floating and fixed point numbers in class a few weeks ago and I thought "Wow, I'll never use this", but here we go, I know the explanation to this because of that class!

alexandresilva
Автор

yo dude love your shorts keep it up <3
i dont even code xD

reycors
Автор

Never ever use floating point arithmetic for basic money calculations. Always use decimal or other fixed point representations

cn-ml
Автор

this happens in all languages
And is why you don't ever use floating point numbers for currency
import your the Decimal class for your langauge

ripp_
Автор

In this case, would be recommended if you use the round () function to get the nearest integer?

PharaelMartins
Автор

similar to the whole 0.1 + 0.2 situation

krispyking
Автор

It's because a PC is dumber than me.

IIdo.
Автор

That's why my teacher always want us to do like
a = float(0.5) instead of a = 0.5

IchorDragon
Автор

use binary coded decimals for currencies, at least that is how I learned it

eternalunion
Автор

This is in literally every language that has floats?

HalfAsleepSam
Автор

This is something that has to do with Numerical Methods

whittakertheo
Автор

Just wait until he discovers JavaScript. There is no solution for that.

wolffwolfie
Автор

Represent money with the smallest possible value, cents

dadutchboy