]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use Math.floor instead of casting to int when trimming decimals. (#16926)
authorSauli Tähkäpää <sauli@vaadin.com>
Wed, 25 Feb 2015 21:19:30 +0000 (23:19 +0200)
committerSauli Tähkäpää <sauli@vaadin.com>
Wed, 11 Mar 2015 06:38:58 +0000 (08:38 +0200)
Change-Id: I02802b910d0dc90221483fedbf05be48958d8dcc

server/src/com/vaadin/ui/Slider.java
server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java

index dad4d295bf1d46470811444e1145e2e1c2195c10..fab6e33caec91e109765b259c79f39b18e9b6623 100644 (file)
@@ -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);
index 48bba8a853e71debcf313ab4e58b0915fcdea066..d2e2654cbc7addb5d6153205ae984cccfeb7feca 100644 (file)
@@ -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));
     }
 }