## What's wrong with float numbers?

A forum for general discussion of the Python programming language.

### What's wrong with float numbers?

I'm using Python 3.2.3. I can't find difference with float numbers. There have code and screen shot of error about that. Please help me...

Code: Select all
`Difference = 0A = float(input ('Input Number 1 :- '))B = float(input ('Input Number 2 :- '))Difference = A-Bprint ('Difference is',Difference)`

Untitled.jpg (132.54 KiB) Viewed 387 times
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm

### Re: What's wrong with float numbers?

The problem is that base 2 can't represent base 10 fractions particularly well.

Read this:
http://docs.python.org/2/tutorial/floatingpoint.html

-Mek

Edit:
This is probably what you want:
Code: Select all
`a = float(input("Enter first number: "))b = float(input("Enter second number: "))difference = a-bprint ("Difference is: {:.2f}".format(difference))`
Code: Select all
`>>> Enter first number: 25.25Enter second number: 45.55Difference is: -20.30>>> `
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1452
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: What's wrong with float numbers?

Mekire wrote:The problem is that base 2 can't represent base 10 fractions particularly well.

Read this:
http://docs.python.org/2/tutorial/floatingpoint.html

-Mek

Edit:
This is probably what you want:
Code: Select all
`a = float(input("Enter first number: "))b = float(input("Enter second number: "))difference = a-bprint ("Difference is: {:.2f}".format(difference))`
Code: Select all
`>>> Enter first number: 25.25Enter second number: 45.55Difference is: -20.30>>> `

Thank you Mekire. I solved that problem with your help. Thank you Sooo Much...
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm

Return to General Discussions

### Who is online

Users browsing this forum: No registered users and 2 guests