For example, when I have 3.333 and when that code is executed, I need the number to be 3.33.
This is the code I have which should be doing that, but doesn't:
String number = Double.toString(first);
number = number.substring(0, string.length() - 1);
first = Double.parseDouble(number);
I tried doing it by converting the number to a string, cutting off last character and saving it into a double again. But it doesn't work. Instead of cutting off 1 digit, it cuts off 2, for example above it would return 3.3.
Is this method reliable and if yes, what can I do to fix it?
Also, is there a chance for this method to crash the program (only decimal numbers go through that code) and would there be a loss in precision?