문제

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