gpt4 book ai didi

JavaFX如何对绑定(bind)数字进行Math.round?

转载 作者:行者123 更新时间:2023-12-01 22:21:49 24 4
gpt4 key购买 nike

如何在 JavaFX 中舍入绑定(bind)数字( double )?我需要将数字四舍五入到小数点后 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);

我可以做到以下几点

c.bind(a.divide(b));

但这显然不会四舍五入。有任何想法吗?谢谢。

最佳答案

c.bind(Bindings.createDoubleBinding(
() -> Math.round(1000.0*a.get()/b.get())/1000.0,
a, b));

关于JavaFX如何对绑定(bind)数字进行Math.round?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39618522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com