Skip to content

Commit 116e495

Browse files
committed
Fix decimal value #107
1 parent 6966f40 commit 116e495

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@ <h1>jQuery Knob</h1>
156156
<input class="knob" data-angleOffset=-125 data-angleArc=250 data-fgColor="#66EE66" data-rotation="anticlockwise" value="35">
157157
</div>
158158
<div class="demo" >
159-
<p>&#215; 5-digit values, step 1000</p>
159+
<p>&#215; 4-digit, step 0.1</p>
160160
<pre>
161-
data-step="1000"
162-
data-min="-15000"
163-
data-max="15000"
161+
data-step=".1"
162+
data-min="-10000"
163+
data-max="10000"
164+
value="0"
164165
data-displayPrevious=true
165166
</pre>
166-
<input class="knob" data-min="-15000" data-displayPrevious=true data-max="15000" data-step="1000" value="-11000">
167+
<input class="knob" data-min="-10000" data-displayPrevious=true data-max="10000" data-step=".1" value="0">
167168
</div>
168169
<div style="clear:both"></div>
169170
<div style="text-align: center">

js/jquery.knob.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
function () {
157157
var val = {};
158158
val[k] = $this.val();
159-
s.val(val);
159+
s.val(s._validate(val));
160160
}
161161
);
162162
});
@@ -452,7 +452,8 @@
452452
};
453453

454454
this._validate = function (v) {
455-
return (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step;
455+
var val = (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step;
456+
return Math.round(val * 100) / 100;
456457
};
457458

458459
// Abstract methods
@@ -549,7 +550,7 @@
549550
a += this.PI2;
550551
}
551552

552-
ret = ~~ (0.5 + (a * (this.o.max - this.o.min) / this.angleArc)) + this.o.min;
553+
ret = (a * (this.o.max - this.o.min) / this.angleArc) + this.o.min;
553554

554555
this.o.stopper && (ret = max(min(ret, this.o.max), this.o.min));
555556

@@ -635,7 +636,7 @@
635636
var v = s.o.parse(s.$.val()) + kv[kc] * m;
636637
s.o.stopper && (v = max(min(v, s.o.max), s.o.min));
637638

638-
s.change(v);
639+
s.change(s._validate(v));
639640
s._draw();
640641

641642
// long time keydown speed-up

0 commit comments

Comments
 (0)