#Extracting fractional part out of float

33 messages · Page 1 of 1 (latest)

upper temple
#

Floats will always have that issue

#

It's due to the way that floating point values are stored in binary on the computer

#

No not really, but you most likely will never need it to be that precise

#

I would suggest using the fraction library

#

!exec ```py
import fractions

print(0.1 + 0.2)
print(fractions.Fraction(0.1 + 0.2).limit_denominator())

stuck yarrowBOT
stuck yarrowBOT
# upper temple !exec

@upper temple

✅ Exec - Success (Super User 🦸)
0.30000000000000004
3/10

upper temple
#

How so

#

That doesn't sound like it matters

upper temple
#

Especially if you're doing arithmetic operations

#

!eval str(0.1+0.2)

stuck yarrowBOT
#
Staff only command

The eval command is currently only available to the server staff.

upper temple
#

!eval str(0.1).split(".")[1]

stuck yarrowBOT
upper temple
#

!eval str(0.1+0.2).split(".")[1]

stuck yarrowBOT
upper temple
#

!eval repr(0.1)

stuck yarrowBOT
upper temple
#

Idk, you're too hung up on a fantasy ideal of precision when you're limited by the hardware that python runs on

#

Okay okay

#

I find that hard to believe

#

It's a limitation with storing decimal values in binary

#

So it doesn't matter the language

sleek gyro
#

i remember there was a way

#

i forgot the way

#

nvm wang did a great job

upper temple
sleek gyro
#

aww