I have a double val
and I'm trying to turn it to float ( cause the function I need to pass it next takes floats ) but I have failed.
I have tried to a) turn it to double and then using Float.parseFloat
and b) turn it to a String.
Below is my code :
DecimalFormat df = new DecimalFormat("#.##");
df.setMaximumFractionDigits(2);
df.setRoundingMode(RoundingMode.CEILING);
Log.i(TAG, "FORMAT = " +df.format(val) );
String valString = String.valueOf(df.format(val));
Log.i(TAG, "valString == " + valString );
float val2 = Float.parseFloat(valString);
but when I'm passing either the double or the String to Float.parseFloat
I get back the previous float values.
Example :
FORMAT = 42.86
valString == 42.86
val== 42.857142857142854 **** why?