I have reviewed a number of threads related to formatting numbers. For the most part it works except for the value 3.101. Float and Double have been used along with the ## and 00 format.
import java.text.DecimalFormat;
public class DecimalFormatTest {
public static void main(String[] args)
{
Float d1 = -3.1011f;
Double ds = -3.1011;
DecimalFormat df = new DecimalFormat("#.##");
System.out.println (Double.valueOf(df.format(d1)));
System.out.println (Double.valueOf(df.format(ds)));
DecimalFormat df2 = new DecimalFormat("#.00");
System.out.println (Double.valueOf(df2.format(d1)));
System.out.println (Double.valueOf(df2.format(ds)));
}
}
The output is :
-3.1
-3.1
-3.1
-3.1
Expected output :
-3.10
-3.10
-3.10
-3.10
As mentioned above, this works for all the other numbers I have tested. For some reason this is causing an issue.
Any ideas as to what makes this number so different and what extra step is needed to get the 2nd digit?
Keep in mind, the key is that I want to eventually return a Float or Double.