I'm using an application which uses mm and inches to draw scaled drawings. I need to convert from one to another without losing precision. I'm struggling with accuracy and have turned to the Apfloat package. Can someone explain... if I start with 100mm, convert it to inches and then back again to Mm why I get a loss of precision??
public static void main(String[] args) {
Apint mm = new Apint(100);
System.out.println("mm = " + mm);
// 25.4mm in 1 inch
Apfloat toInches = new Apfloat("25.4");
// 100mm / 25.4 = x-Inches
Apfloat inches = mm.divide(toInches);
System.out.println("mm - > Inch = " + inches);
// x-Inches x 25.4 = 100mm
Apfloat backToMm = inches.multiply(toInches);
System.out.println("Inch - > mm = " + backToMm);
}
Outputs:
mm = 100
mm - > Inch = 3.93
Inch - > mm = 9.99e1
No matter how big I set the precision property I still get the reoccurring 9.999...