Convert weight to cash [closed]

0

I'm trying to convert weight into cash, but every time my answer is zero and I calculated here and nn should give zero kkkkk can somebody help me obs: o 5 is the price per kilo (This work will make me pass as standard give me a help pf kkkkk)

private void convertButtonActionPerformed(java.awt.event.ActionEvent evt){                                              

    double pesagem = Double.parseDouble(peso.getText());
    double Result = ((5/1000)*pesagem);
    textresult.setText("R$ "+Result);
}    
    
asked by anonymous 20.11.2016 / 18:56

1 answer

5

When you use int in a division, the result will be rounded. So to solve your problem, change the result calculation to:

double Result = ((5.0 / 1000.0) * pesagem);

Hint: Do not use variables starting with a capital letter to abide by the Java naming convention. Use as follows:

double result = ((5.0 / 1000.0) * pesagem);
    
20.11.2016 / 19:40