I am trying to correctly convert (parse) a string to float in java, for the number 5755.1115, example:
float fl = new BigDecimal("5755.1115").floatValue();
float fl = (float)5755.1115d;
The issue is that it always prints 5755.1113. It seems it loses precision (I also tried using MathcContext(10) for example but didn't work)
But if I try this in javascript it seems it is working:
var fl = parseFloat('5755.1115');
var str = "" + fl.toPrecision(8);
console.log("number: " + str);
It prints the number correctly even if I don't use toPrecision() function.
Can anyone explain how can I achieve this also in Java?
EDIT: My mistake, I forgot to specify that I do not want to use double because I need to keep the data transmission at minimum.