I am making an app, and I used decimal format to round numbers. It worked fine till 5-6 digits but only rounds to 2 decimals.
I made some edits but it didn't work.Till 5-6 digits,It rounds perfectly, i.e. leaving only 3 decimal places after rounding,but when I go over 7-8,It just rounds two decimal places
This is my code
double result = Double.parseDouble(myEditText.getText().toString());
String i = Double.toString(result);
int int1 = i.indexOf(".");
String io = "0.";
int ii = (i.length() - int1 - 1)-3;
for (int iio = 0;iio <= ii;iio++){
io = io+"#";
}
DecimalFormat decimalFormat = new DecimalFormat(io);
String string = decimalFormat.format(result);
result = Double.parseDouble(string);
textArea.setText(textArea.getText().toString() + " = "+result);
For eg. I input 1.678394762 It gives me 1.6783948, While it should give 1.678 If I input 1.45678,It gives me expected 1.457