I am having a problem with the Math.floor javascript function for the script below:
1) from a value between 8192 and 10484,
if I type 8192.8 -> The Math.floor converts it into 8192.79 if I type 8192.88 -> The Math.floor converts it into 8192.87 if I type 8192.3 -> The Math.floor converts it into 8192.29
The strange part is that, with the exception of the range indicated above, the function works fine.
HTML: <div data-bind="text: popIncrease"></div> <input type="text" data-bind="value: userInput, valueUpdate: 'afterkeydown'" /> Javascript: var ViewModel = function () { var _self = this; _self.userInput = ko.observable(); _self.popIncrease = ko.computed(function () { return parseFloat((Math.floor(_self.userInput() * 100) / 100)).toFixed(2); }); }; ko.applyBindings(new ViewModel());
jsfiddle: https://jsfiddle.net/91z5bdy4/1/
When I changed 100 from 1000, he solved the error, but I donβt understand why this happened in the first place?
ron_meh
source share