java problem within while loop and count variable..
i have a program that breaks up the ammount of change given into the corosponding number of quarters dimes nickels and pennies.. anyway for some reason im not getting the correct number of pennies its off by one.. every time except for the input .07 this gives the correct ammount but .08 gives the same as .07
Code:
import java.util.*; |
Floating point arithmetic is inexact. You are dealing with periodic fractions - even if think you don't - because your computer works in radix 2 and not in radix 10.
Before ever using floating point in whatever programming language read and understand http://en.wikipedia.org/wiki/Floating_point . Again, your problem has nothing to do with Java. To resolve your problem deal with integers only, i.e. scale up everything by 100. |
All times are GMT -5. The time now is 12:15 PM. |