Skip to content

Instantly share code, notes, and snippets.

@ptldhaval
ptldhaval / filter.js
Last active May 8, 2018 13:57
Angular filter to convert numbers to thousand suffixes (1234 > 1.2k)
/*Initial Referance taken from https://gist.github.com/thewarpaint/889690aeb21a8dfd7aba and modified as per the requirement.*/
angular.module('Utils',[]).filter('isoCurrencyWithK', ["$filter", "iso4217", function ($filter, iso4217) {
return function (amount, fraction, currencyCode) {
var exp = 0, rounded, currency, nagative, suffixes = ['','K', 'M', 'G', 'T', 'P', 'E'];
//set decimal amount. Default 0
var fractionSize = fraction === void 0 ? 0 : fraction;
//check if the amount is more than 1000
//if yes, set suffix for the amount
if(amount >= 1000 || amount < -1000 ) {