So I wanted to round my double values into numbers that contain only 2 decimals but cant figure out how to do it. How can I change my code in order to get 2 values that are rounded for 2 decimals? Any help with this would be appreciated.
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
num1 = Double.parseDouble(numBase.getText().toString());
num2 = Double.parseDouble(numNikotin.getText().toString());
sum = num1 / 20 * num2;
String resultN = Double.toString(sum);
String.format("%.2f", resultN);
addResult.setText(resultN);
sum = num1 - sum;
String resultB = Double.toString(sum);
String.format("%.2f", resultB);
addResult2.setText(resultB);
}
});