summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2015-02-25 23:19:30 +0200
committerSauli Tähkäpää <sauli@vaadin.com>2015-03-11 08:38:58 +0200
commit155ffa7560e6445557ad2d04d2f83411c391debb (patch)
tree22bc0ff89f6b5ef9e1e0e24a5bf393122ea436cf /server
parent21c73437439539276c6f4152fa149c201db94d95 (diff)
downloadvaadin-framework-155ffa7560e6445557ad2d04d2f83411c391debb.tar.gz
vaadin-framework-155ffa7560e6445557ad2d04d2f83411c391debb.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.java2
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java9
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));
}
}