I am building an angular app involving large amounts. I'd like to shorten the way their are displayed so I built a quick and dirty filter replacing '1000000000' by '$1.0Bn' for example but it is really dirty and it just truncate the numbers instead of rounding them up.
Here it is:
.filter('largeAmountCurrency', function() {
return function(input) {
if (!input) return;
var oneBillion = 1000000000,
oneMillion = 1000000;
if (input > oneBillion)
return '$' + parseInt(input / oneBillion) + '.' +
String(parseInt(input - parseInt(input/oneBillion))).substring(1,3) + 'Bn';
if (input > oneMillion)
return '$' + parseInt(input / oneMillion) + '.' +
String(parseInt(input - parseInt(input/oneMillion))).substring(1,3) + 'M';
return input;
}
});
Is their any prebuilt filter in angular which does this job? Or how can I shorten it dramatically?