JavaFX如何将Math.round绑定一个数字?

bsh*_*hek 2 javafx javafx-8

如何在JavaFX中对绑定数字(双精度)进行舍入?我需要将数字四舍五入到小数点后3位.所以我需要更改实际值而不是值的外观.我基本上想要这样做:

 DoubleProperty a= new SimpleDoubleProperty(2.015);
 DoubleProperty b= new SimpleDoubleProperty(9.265);
 DoubleProperty c= new SimpleDoubleProperty();
 c.bind(Math.round(a.divide(b)*1000d)/1000d);
Run Code Online (Sandbox Code Playgroud)

我可以做以下事情

c.bind(a.divide(b));
Run Code Online (Sandbox Code Playgroud)

但这显然不会使数字四舍五入.有任何想法吗?谢谢.

Jam*_*s_D 7

c.bind(Bindings.createDoubleBinding(
    () -> Math.round(1000.0*a.get()/b.get())/1000.0,
    a, b));
Run Code Online (Sandbox Code Playgroud)