Skip to content

Commit

Permalink
fix(percentage): fix the result for 0 and other edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
assisrafael committed Apr 7, 2015
1 parent ba9bdf7 commit 5d0f456
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/global/percentage/percentage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ angular.module('ui.utils.masks.global.percentage', [
if(isNaN(decimals)) {
decimals = 2;
}

var numberDecimals = decimals + 2;
var viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter),
modelMask = NumberMasks.modelMask(numberDecimals);

ctrl.$formatters.push(function(value) {
if(!value) {
function formatter(value) {
if(ctrl.$isEmpty(value)) {
return value;
}

var valueToFormat = preparePercentageToFormatter(value, decimals);
return viewMask.apply(valueToFormat) + ' %';
});
}

function parse(value) {
if(!value) {
if(ctrl.$isEmpty(value)) {
return value;
}

Expand All @@ -58,6 +59,7 @@ angular.module('ui.utils.masks.global.percentage', [
return actualNumber;
}

ctrl.$formatters.push(formatter);
ctrl.$parsers.push(parse);

if (attrs.uiPercentageMask) {
Expand Down

0 comments on commit 5d0f456

Please sign in to comment.