aspose file tools*
The moose likes Java in General and the fly likes Decimals not converting to correct fractions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Decimals not converting to correct fractions" Watch "Decimals not converting to correct fractions" New topic
Author

Decimals not converting to correct fractions

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. Awhile back, I found a class that takes a decimal value and converts it to a fraction. It seemed to have been working OK, but a couple of users noticed some decimal values not converting properly.
The two they've noticed so far are :
.781 should convert to 25/32, but it's converting to 7/9.
.625 should convert to 3/8, but it's converting to 3/5.
I tried to look at the code and figure out what was going on, but I guess I really don't understand everything that is going on to get fraction values.
Could someone take a look at the method that is supposed to be converting the value to a fraction, and help me understand why it is doing it?
Here's the method: (Sorry it's so long)

I appreciate ANY help anyone can give me on this. Thanks again!!
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Try this:

[ November 14, 2003: Message edited by: Tom Blough ]
[ November 14, 2003: Message edited by: Tom Blough ]

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Jaap van Hengstum
Greenhorn

Joined: Jul 24, 2003
Posts: 24
Using continued fractions (I hope I've done this correctly since it was very late ):
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decimals not converting to correct fractions