How do I convert a double to a fraction in a format suitable for representing inches?
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 .031开发者_运维技巧25 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".
can you multiply the fractional part by 32 then round?
精彩评论