Created
January 11, 2014 19:29
-
-
Save rayshan/8375589 to your computer and use it in GitHub Desktop.
JavaScript Math.round has issues with floats. This gives correct result. Inspiration: http://stackoverflow.com/questions/20701029/rounding-issue-in-math-round-tofixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app').filter 'round', () -> | |
(input, decimals) -> | |
return Math.round(input * Math.pow(10, decimals)) / Math.pow(10, decimals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RoundNum(num, length) { | |
var number = Math.round(num * Math.pow(10, length)) / Math.pow(10, length); | |
return nnumber; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment