| Author |
Decimal Place Problem
|
Timothy Sam
Ranch Hand
Joined: Sep 18, 2005
Posts: 746
|
|
Hi guys, I can't get the right decimal format to print on my screen. Here's an example. Zoom Percentage: 9/128 = 0.0 Zoom Percentage: 7/26 = 0.0 Zoom Percentage: 5/26 = 0.0 Zoom Percentage: 7/19 = 0.0 Zoom Percentage: 2/19 = 0.0 Zoom Percentage: 3/18 = 0.0 Zoom Percentage: 2/18 = 0.0 Zoom Percentage: 1/14 = 0.0 Zoom Percentage: 2/14 = 0.0 Zoom Percentage: 1/12 = 0.0 Zoom Percentage: 0/12 = 0.0 Zoom Percentage: 0/14 = 0.0 Zoom Percentage: 5/14 = 0.0 Zoom Percentage: 3/13 = 0.0 Zoom Percentage: 0/13 = 0.0 Zoom Percentage: 0/9 = 0.0 Zoom Percentage: 0/9 = 0.0 Zoom Percentage: 0/10 = 0.0 Zoom Percentage: 1/10 = 0.0 Zoom Percentage: 1/5 = 0.0 The quotient always print as 0.0 where something like 9/128 should equal 0.0703125. Why is it? Here's the method where I do this stuff... Thank you for your kind answers...
|
SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
In this line, you are doing an integer division, not a floating point division (even though zoomPercentage is a float). The result of the integer division is 0 and that's converted to a float. Convert at least one of the numbers in the division to a float:
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Timothy Sam
Ranch Hand
Joined: Sep 18, 2005
Posts: 746
|
|
|
Hi! Thanks! The solution worked perfectly!
|
 |
 |
|
|
subject: Decimal Place Problem
|
|
|