By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,773 Members | 914 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,773 IT Pros & Developers. It's quick & easy.

Decimals in python

P: n/a
Hello. New to using Python. Python automatically round off watver i
calculate using the floor function. How wud i make the exact value
appear?

Tried out fabs() in the math library but still confused. Cud some1
elaborate on it.
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies

P: n/a
ar**********@gmail.com wrote:
Hello. New to using Python. Python automatically round off watver i
calculate using the floor function. How wud i make the exact value
appear?

Tried out fabs() in the math library but still confused. Cud some1
elaborate on it.
If you're working with integers, the result will always be an integer:
>>a = 10/3
print a
3

How ever if you add a float into the mix:
>>a = 10/3.0
print a
3.3333333333333335

HTH
Jun 27 '08 #2

P: n/a
ar**********@gmail.com wrote:
Hello. New to using Python. Python automatically round off watver i
calculate using the floor function. How wud i make the exact value
appear?

Tried out fabs() in the math library but still confused. Cud some1
elaborate on it.
[python]
---help(math.floor):
Help on built-in function floor in module math:

floor(...)
floor(x)

Return the floor of x as a float.
This is the largest integral value <= x.
[/python]

The whole point of floor() is to round down. If you want to see all the
decimals, don't use floor(), and follow Aidan's advice to have at least
one floating-point number in the calculation.
--
Ethan
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.