質問

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