From 116e4959738c74126a50b6eb3d335194d270e5ca Mon Sep 17 00:00:00 2001 From: aterrien Date: Tue, 2 Sep 2014 23:11:16 +0200 Subject: [PATCH] Fix decimal value #107 --- index.html | 11 ++++++----- js/jquery.knob.js | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 3928f0c..81f8d7b 100755 --- a/index.html +++ b/index.html @@ -156,14 +156,15 @@

jQuery Knob

-

× 5-digit values, step 1000

+

× 4-digit, step 0.1

-data-step="1000"
-data-min="-15000"
-data-max="15000"
+data-step=".1"
+data-min="-10000"
+data-max="10000"
+value="0"
 data-displayPrevious=true
             
- +
diff --git a/js/jquery.knob.js b/js/jquery.knob.js index 92b76db..09ce362 100755 --- a/js/jquery.knob.js +++ b/js/jquery.knob.js @@ -156,7 +156,7 @@ function () { var val = {}; val[k] = $this.val(); - s.val(val); + s.val(s._validate(val)); } ); }); @@ -452,7 +452,8 @@ }; this._validate = function (v) { - return (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step; + var val = (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step; + return Math.round(val * 100) / 100; }; // Abstract methods @@ -549,7 +550,7 @@ a += this.PI2; } - ret = ~~ (0.5 + (a * (this.o.max - this.o.min) / this.angleArc)) + this.o.min; + ret = (a * (this.o.max - this.o.min) / this.angleArc) + this.o.min; this.o.stopper && (ret = max(min(ret, this.o.max), this.o.min)); @@ -635,7 +636,7 @@ var v = s.o.parse(s.$.val()) + kv[kc] * m; s.o.stopper && (v = max(min(v, s.o.max), s.o.min)); - s.change(v); + s.change(s._validate(v)); s._draw(); // long time keydown speed-up