I am having a double variable:
private double b=0.0;
I am taking value of a certain field in b (the value is between 0.0 to 9.99999999). Mostly, user enters value between 0.0 to 1.0.
When I am saving the value from user in ‘b’, and if the value is 0.000001, then it is getting saved as 1E-6 and next time displayed as same on the screen (this is because b is Double).
Is there any way (just by calling some method) in Java, that I can avoid the conversion of value to 1E-6 format? I want to save the value as entered by user only (0.000001).
The double isn’t actually “saved” as a string at all. That’s just a matter of formatting – for which you should see
DecimalFormat. However, it definitely won’t be exactly 0.000001 because that number isn’t exactly representable as a double. I would strongly recommend that you useBigDecimalinstead when precise decimal values matter (as it sounds like they do here).