diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2015-02-25 23:19:30 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2015-03-11 12:54:07 +0200 |
commit | ea11bcc7603f9197097e6cca3ea7ee11729037aa (patch) | |
tree | 651600cea1ebab38ea951edcc463f39472649dcc /server | |
parent | cae3a986f21022ca92d98e8820bd7d4b34e869f2 (diff) | |
download | vaadin-framework-ea11bcc7603f9197097e6cca3ea7ee11729037aa.tar.gz vaadin-framework-ea11bcc7603f9197097e6cca3ea7ee11729037aa.zip |
Use Math.floor instead of casting to int when trimming decimals. (#16926)
Change-Id: I02802b910d0dc90221483fedbf05be48958d8dcc
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/Slider.java | 2 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java index dad4d295bf..fab6e33cae 100644 --- a/server/src/com/vaadin/ui/Slider.java +++ b/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); diff --git a/server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java b/server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java index 48bba8a853..d2e2654cbc 100644 --- a/server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java +++ b/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)); } } |