Rounding up doubles to 2 decimal places
807599Apr 17 2007 — edited Apr 18 2007Hi i have written a simple project to convert currency which is working fine but i am struggling to figure out how to round the outputs to two decimal places. E.g. 1.563434 would equal 1.56. Here is the program i have written but i do not know where to add the math instruction or which to use as there seems to be many different ways. Thanks
double x;
double y;
double z;
x = Integer.parseInt(txtInput.getText());
y = 0.748279;
z = Double.parseDouble(txtExchange.getText());
if (z > 0)
txtOutput.setText('?' + Double.toString( x * z ));
else
txtOutput.setText('?' + Double.toString( x * y ));