I have a JSON source from an API at work, where I have to get a balance from the JSON response, so the value is very important. That amount comes in xx.xxxxxxxxxxxxxx (usually two digits followed by a maximum of 14 decimals).
I am working with JAVA. It doesn't matter what I try, the output is always the same. The console says it's a float, I can't cast it to any other formats. And the weirdest thing is that the number shown is wrong. For example, I am getting 803.599310421 in the JSON response, and when I print out the value, it says 803.5989647583. Same number but different decimals.
How do I get this accurately? Because frankly, I don't want to parse it as a string. The only way I could get the same value from the JSON was with substring.
Here's the code I'm using:
JsonPath jsonobject = httpRequest2.jsonPath();
float myFloatValue = jsonobject.get("data[0].balance");
System.out.println(myFloatValue);
Here's a sample of the value in the JSON: 903.40019831 Here's what Sysout prints: 903.4004 or 903.4003987 Completely useless, please help!