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.

有帮助吗?

解决方案 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

其他提示

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));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top