I'm using the ng-currency library - http://aguirrel.github.io/ng-currency/ - to display currency values in a project. However, it's not exactly what I need, the currency value
- cannot be negative
- cannot be greater than 999,999,999
- must be rounded to the nearest whole number i.e. contain no decimal
- rendered as a currency value, i.e. 1234 is displayed as $1234.00
I've forked the project here - https://github.com/tetsujin1979/ng-currency/blob/master/src/ng-currency.js I removed the minus symbol from the regular expressions to stop users entering negative values, and edited the on blur method to round the figures before displaying them, as shown below, but when the rounded value is greater than $999,999.00, the model isn't getting the assigned values
element.on("blur", function () {
var roundedValue = Math.round(ngModel.$modelValue);
if(roundedValue > 999999999) {
roundedValue = 999999999;
}
ngModel.$setViewValue(roundedValue);
element.val($filter('currency')(roundedValue, currencySymbol()));
ngModel.$render();
});
I've created a plunkr here to demonstrate this here: http://plnkr.co/Y7WkJtjlDZF3pXo84MRs