Here's html:
<body>
<p>
<img src="http://i.imgur.com/yOadS1c.png" id="minus1" width="20" height="20" class="minus"/>
<input id="qty1" type="text" value="1" class="qty"/>
<img id="add1" src="http://i.imgur.com/98cvZnj.png" width="20" height="20" class="add"/>
</p>
</body>
Here's js:
$(function () {
$('.add').on('click',function(){
var $qty=$(this).closest('p').find('.qty');
var currentVal = parseFloat($qty.val());
if (!isNaN(currentVal)) {
$qty.val(currentVal + 0.1);
}
});
$('.minus').on('click',function(){
var $qty=$(this).closest('p').find('.qty');
var currentVal = parseFloat($qty.val());
if (!isNaN(currentVal) && currentVal > 0) {
$qty.val(currentVal - 0.1);
}
});
});
jsfiddle: http://jsfiddle.net/hMS6Y/30/
When i try to increase or decrease input value by 0.1 i am getting some strange values like:
1.1 is ok 1.2000000000000002 1.3000000000000003
how can i make them look: 1.1, 1.2, 1.3 and so on.