Dan Dean
2013-08-30 16:00:29 UTC
Hello,
I found a example how to format numeric values (doubles) with proper
format, or believed so :) I have a filter like following
/**
* Created with JetBrains WebStorm.
*/
angular.module('filters').filter('money', function(input, curSymbol,
decPlaces,
thouSep, decSep) {
var curSymbol = curSymbol || ""; <!-- Symbol not needed -->
var decPlaces = decPlaces || 2;
var thouSep = thouSep || " ";
var decSep = decSep || ",";
// Check for invalid inputs
var out = isNaN(input) || input === '' || input === null ? 0.0 :
input;
//Deal with the minus (negative numbers)
var minus = input < 0;
out = Math.abs(out);
out = angular.filter.number(out, decPlaces);
// Replace the thousand and decimal separators.
// This is a two step process to avoid overlaps between the two
if(thouSep != " ") out = out.replace(/\ /g, "T");
if(decSep != ",") out = out.replace(/\,/g, "D");
out = out.replace(/T/g, thouSep);
out = out.replace(/D/g, decSep);
// Add the minus and the symbol
if(minus){
return "-" + curSymbol + out;
}
else{
return curSymbol + out;
}
});
and a small tester to this question
<!doctype html>
<html ng-app>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js">
</script>
</head>
<body>
<div ng-controller="Ctrl">
<input ng-model="Field" type="text"><br>
No filter: {{Field}}<br>
Reverse: {{Field|money}}<br>
</div>
</body>
</html>
BUT I haven't get it working it throws error
1 Error: Unknown provider: moneyFilterProvider <- moneyFilter
Can anyone please show what is wrong?
Best Regards Dan
I found a example how to format numeric values (doubles) with proper
format, or believed so :) I have a filter like following
/**
* Created with JetBrains WebStorm.
*/
angular.module('filters').filter('money', function(input, curSymbol,
decPlaces,
thouSep, decSep) {
var curSymbol = curSymbol || ""; <!-- Symbol not needed -->
var decPlaces = decPlaces || 2;
var thouSep = thouSep || " ";
var decSep = decSep || ",";
// Check for invalid inputs
var out = isNaN(input) || input === '' || input === null ? 0.0 :
input;
//Deal with the minus (negative numbers)
var minus = input < 0;
out = Math.abs(out);
out = angular.filter.number(out, decPlaces);
// Replace the thousand and decimal separators.
// This is a two step process to avoid overlaps between the two
if(thouSep != " ") out = out.replace(/\ /g, "T");
if(decSep != ",") out = out.replace(/\,/g, "D");
out = out.replace(/T/g, thouSep);
out = out.replace(/D/g, decSep);
// Add the minus and the symbol
if(minus){
return "-" + curSymbol + out;
}
else{
return curSymbol + out;
}
});
and a small tester to this question
<!doctype html>
<html ng-app>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js">
</script>
</head>
<body>
<div ng-controller="Ctrl">
<input ng-model="Field" type="text"><br>
No filter: {{Field}}<br>
Reverse: {{Field|money}}<br>
</div>
</body>
</html>
BUT I haven't get it working it throws error
1 Error: Unknown provider: moneyFilterProvider <- moneyFilter
Can anyone please show what is wrong?
Best Regards Dan
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.