Convert weight into money

Asked

Viewed 67 times

0

I’m trying to convert weight into money, but every time my answer is zero and I calculated here and nn should give zero kkkkk someone can help me Obs: the 5 is the price per kilo (This job will make me pass the series give me a help pf kkk)

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

    double pesagem = Double.parseDouble(peso.getText());
    double Result = ((5/1000)*pesagem);
    textresult.setText("R$ "+Result);
}    
  • 1

    Peso in cash? What is this conversion? Edit the question there, it is quite difficult to understand.

  • The program is for a Gelateria where the employee type the weight of the ice cream and the software calculate and turns into money according to the price per kilo

  • 1

    Then edit the question and give more details about what you are doing (as you did in the comments), otherwise it is difficult to understand the problem.

  • Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).

1 answer

5

When you use a 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);

Tip: Do not use variables starting with a capital letter to comply with the naming convention Java. Use as follows:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.