I tried to make a small program that converts miles to kilometers back and forth, but whenever the number has 4 digits, the program instantly freezes
parts of code :
private double KmToMiles(double inputValue) {
return(inputValue * 1.609344);
}
private double MilesToKm(double inputValue) {
return(inputValue * 0.621372);
}
also
double inputValue = Double.parseDouble(text.getText().toString());
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
text.setText(String.valueOf(nf.format(KmToMiles(inputValue))));
text.setText(String.valueOf(nf.format(MilesToKm(inputValue))));
jednotka.setText("kilometers");
km.setChecked(false);
How do i make so the value returned has a small amount of decimals without retrieving error? If i swap double with integer and remove the number formatting, i get no error but the conversion is inaccurate with no decimals. Using doubles without NF i get too many decimals