-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filters): percentage filter implementation
This commit adds in a simply percentage filter for adding percent (%) signs to numbers. If the input is not a number, the percent filter does not do anything
- Loading branch information
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
angular.module('bhima.filters') | ||
.filter('percentage', PercentageFilter); | ||
|
||
/** | ||
* Percentage Filter | ||
* | ||
* The percentage filter accepts a number and returns it as a percentage. | ||
*/ | ||
function PercentageFilter() { | ||
return function percentage(number) { | ||
|
||
// escape if no input was passed in | ||
if (angular.isUndefined(number)) { return ''; } | ||
|
||
// cast value as number (or NaN) | ||
var value = Number(number); | ||
|
||
// angular's isNumber() method reports NaNs as numbers | ||
if (!angular.isNumber(value) || isNaN(value)) { return number; } | ||
|
||
// return the value + a percentage sign | ||
return value + '%'; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters