Skip to content

Instantly share code, notes, and snippets.

@pedrorocha-net
Created October 29, 2014 18:47
Show Gist options
  • Save pedrorocha-net/9aa21d5f34d9cc15d18f to your computer and use it in GitHub Desktop.
Save pedrorocha-net/9aa21d5f34d9cc15d18f to your computer and use it in GitHub Desktop.
Angular JS Filter for Number Abbreviation
"use strict"
@Application = angular.module("numberAbbrevFilter", [])
@Application.filter "numberAbbrev", ->
(number) ->
if number >= 10000000
return (number / 1000000).toFixed(0) + 'M'
if number >= 1000000
return (number / 1000000).toFixed(1) + 'M'
if number >= 10000
return (number / 1000).toFixed(0) + 'K'
if number >= 1000
return (number / 1000).toFixed(1) + 'K'
return number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment