Skip to content

Instantly share code, notes, and snippets.

@rayshan
Created January 11, 2014 19:29
Show Gist options
  • Save rayshan/8375589 to your computer and use it in GitHub Desktop.
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
angular.module('app').filter 'round', () ->
(input, decimals) ->
return Math.round(input * Math.pow(10, decimals)) / Math.pow(10, decimals)
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