浏览代码

Use Math.floor instead of casting to int when trimming decimals. (#16926)

Change-Id: I02802b910d0dc90221483fedbf05be48958d8dcc
tags/7.4.2
Sauli Tähkäpää 9 年前
父节点
当前提交
ea11bcc760

+ 1
- 1
server/src/com/vaadin/ui/Slider.java 查看文件

@@ -267,7 +267,7 @@ public class Slider extends AbstractField<Double> {

if (resolution > 0) {
// Round up to resolution
newValue = (int) (v * Math.pow(10, resolution));
newValue = Math.floor(v * Math.pow(10, resolution));
newValue = newValue / Math.pow(10, resolution);
if (getMin() > newValue || getMax() < newValue) {
throw new ValueOutOfBoundsException(newValue);

+ 9
- 0
server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java 查看文件

@@ -65,6 +65,15 @@ public class SliderTest {
} catch (Slider.ValueOutOfBoundsException e) {
// TODO: handle exception
}
}

@Test
public void valueCanHaveLargePrecision() {
Slider slider = new Slider();
slider.setResolution(20);

slider.setValue(99.01234567891234567890123456789);

assertThat(slider.getValue(), is(99.01234567891234567890123456789));
}
}

正在加载...
取消
保存