assylias
assylias

Reputation: 328785

How to bind a DoubleProperty to an expression?

I have a DoubleProperty (price) and I want a second DoubleProperty (discountedPrice) to be bound to price - 25%.

So I thought I would use the multiply method but it does not seem to work as expected:

DoubleProperty price = new SimpleDoubleProperty();
DoubleProperty pctDiscount = new SimpleDoubleProperty();
pctDiscount.bind(price.multiply(0.75));

price.set(100);

System.out.println(pctDiscount);

I was expecting the program to output 75 but the output is:

DoubleProperty [bound, invalid]

Upvotes: 0

Views: 351

Answers (1)

Uluk Biy
Uluk Biy

Reputation: 49205

DoubleProperty is a wrapper class. To get actual value

System.out.println(pctDiscount.getValue());

or

System.out.println(pctDiscount.get());

Upvotes: 4

Related Questions