Question

I have code like this:

double priceMulti = 1.2;
    double price = Double.parseDouble(jTextField1.getText());
  double date = 1980;
  double random = Math.random()*20;
  jLabel28.setText(priceMulti*String.valueOf(price)*date*random);

and in line with setting text I got an error "bad operand types for binary operator "*"" so I cant multiple anything. Edit: main question is Solved, but now I want to use BigDecimal, not Doubles, because they are like 1.000012, and I dunno how.

Was it helpful?

Solution 2

You cannot multiply string by double in Java. You should do multiplication of all the doubles you have and then cast it to string to set the resulting value into Label text

OTHER TIPS

You're trying to multiply a String value with a double value. The arithmetic operators do not work on String values. You need to multiply all the doubles and then get the String value of it to set it to your jLabel28.

jLabel28.setText(String.valueOf(priceMulti * price * date * random));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top