Skip to content

Commit

Permalink
Fix decimal value aterrien#107
Browse files Browse the repository at this point in the history
  • Loading branch information
aterrien committed Sep 2, 2014
1 parent 6966f40 commit 116e495
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ <h1>jQuery Knob</h1>
<input class="knob" data-angleOffset=-125 data-angleArc=250 data-fgColor="#66EE66" data-rotation="anticlockwise" value="35">
</div>
<div class="demo" >
<p>&#215; 5-digit values, step 1000</p>
<p>&#215; 4-digit, step 0.1</p>
<pre>
data-step="1000"
data-min="-15000"
data-max="15000"
data-step=".1"
data-min="-10000"
data-max="10000"
value="0"
data-displayPrevious=true
</pre>
<input class="knob" data-min="-15000" data-displayPrevious=true data-max="15000" data-step="1000" value="-11000">
<input class="knob" data-min="-10000" data-displayPrevious=true data-max="10000" data-step=".1" value="0">
</div>
<div style="clear:both"></div>
<div style="text-align: center">
Expand Down
9 changes: 5 additions & 4 deletions js/jquery.knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
function () {
var val = {};
val[k] = $this.val();
s.val(val);
s.val(s._validate(val));
}
);
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 116e495

Please sign in to comment.