in Jack Shirazi book "Java Performance Tuning", he presents a way to optimize conversion from double to String. the code of the optimization can be found here: http://onjava.com/onjava/2000/12/15/graphics/DoubleToString.java
however, there seem to be some issue with specific numbers for a 2 digits display, when using the method with 0.0951 (until 0.0999) it returns "0.0a", which is obviously incorrect. when running it with 0.0949, it correctly returns 0.09. when running it with 1.0951 it correctly return 1.10.
any idea about what's wrong ? I'm trying to understand the small bits, but haven't found the culprit yet.
here's my test main:
public DoubleToString() {
double d1 = 0.0949;
double d2 = 0.0951;
StringBuffer sb = new StringBuffer();
sb.append("display d1 = ");
appendFormatted(sb, d1, 2, '.', ',', 3, '-', '-');
sb.append(" : ");
appendFormatted(sb, d2, 2, '.', ',', 3, '-', '-');
System.out.println(sb.toString());
}