views:

33

answers:

1

I am using the Apache Commons math.Fraction class to convert my doubles to fractions, which is working fine.

However, I need it to calculate these fractions in a way that makes sense for displaying lengths in inches, to the nearest 1/32".

For example, converting 0.325 to a fraction yields 12/37, which doesn't make sense to someone looking at a US ruler. I suppose I want to round the decimal to the nearest .03125 before i convert it, if that makes sense. My basic math skills are failing me :(

edit To clarify, all the input is in decimal inches between 0 and 1. Given the sample input above, I would want 5/16".

+4  A: 

can you multiply the fractional part by 32 then round?

Marco
thanks marco. this is the painfully obvious answer i was looking for
DustMason