Python : Is a number too big? [duplicate] - python

This question already has answers here:
Why does integer division yield a float instead of another integer?
(4 answers)
Why does floating-point arithmetic not give exact results when adding decimal fractions?
(31 answers)
Closed 1 year ago.
I've learnt that python supports very large numbers with int itself.
But in this case :
print(int(12630717197566440579/10))
My answer is
1263071719756644096
and not
1263071719756644057
As it's supposed to be.
Can someone tell me why?

Related

python float to string in exponent without dot [duplicate]

This question already has answers here:
Use fixed exponent in scientific notation
(3 answers)
Display a decimal in scientific notation
(13 answers)
Closed 3 years ago.
Basically, given a float point number, say
f=0.25
I want
'25e-02'
I would only consider numbers with two decimals. How can I do this without multiplying 100??
If I simply do '%.1e'%0.25, I get '2.5e-01', which is not what I want. I wonder if there is any way that I can choose the number in the exponent part, namely the xx in e-xx.

Decimal rounding in python [duplicate]

This question already has answers here:
Is floating point math broken?
(31 answers)
Floating Point Numbers [duplicate]
(7 answers)
Closed 4 years ago.
I am trying to understand the decimal rounding behavior in python. What I find strange is the following:
1) Multiplying 70 by 11.46950 gives me 802.865
2) Multiplying 70 by 11.46750 gives me 802.7249999999999
Why is there extra precision in the second case and not the first case? I understand that internally, the decimal cannot be represented exactly. But that reason should also apply to the first case as well?
I am using python3.6.
Thanks

python print error, math incorrect (1/10=0) [duplicate]

This question already has answers here:
Script printing all zeros [duplicate]
(2 answers)
Basic python arithmetic - division
(6 answers)
Closed 5 years ago.
when I startup python, I don't import anything and I just enter 1/10, it returns 0. Any idea how to fix this?

(25/10) compared to (25//10) in python [duplicate]

This question already has answers here:
What is the difference between '/' and '//' when used for division?
(16 answers)
Closed 8 years ago.
why does one give a different end result than the other in python. When I type in print(25/10) the result is 2.5.
Yet when I type print(25//10) it is 2. Could anyone tell me why?
// used for Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed.

why float number operate is so strange in python? [duplicate]

This question already has answers here:
Python rounding error with float numbers [duplicate]
(2 answers)
Python floating-point math is wrong [duplicate]
(2 answers)
Closed 9 years ago.
In my python,you can see:
>>> 0.6+0.8
1.4
>>> 1.6+0.8
2.4000000000000004
why the result is so strange?
I believe this is a problem with caluclating floats with binary rather than python,
http://docs.python.org/2/library/decimal.html explains it better than I could, in short
import decimal
num1 = decimal.Decimal("1.6")
num2 = decimal.Decimal("0.8")
num1 + num2
Writing a function to decimal your stuff for you will be easy enough.
This is because of floating point rounding error.
Read basic here: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
And the solution for Python for your case:
http://floating-point-gui.de/languages/python/

Categories

Resources