
Hi, I'm Jon an experienced programmer with a vibrant personality who is passionate about pretty much everything!
I spend much of my time building functional websites bridging the void between robots and humans.
Whenever needing to do Math in computing, you will come across floating point issues. This is the solution I manufactured whilst needing to floor round values to 2 decimal places.
var floorTo = function(val) { var retVal; if((""+val).length > 10) { val = Math.round(val * 10000) / 10000; val = Math.floor(val * 1000) / 1000; var d = String(val); var p = d.split('.'); retVal = d; if (p[1] && p[1].length == 3) { retVal = d.substr(0, (d.length-1)); } return parseFloat(retVal); } retVal = Math.floor(val * 100) / 100; return retVal; } You're welcome!