AngularJS currency filter example
AngularJS currency filter will return string by formatting the given number.
Example:- Input amount :
- Default currency filter, if we have not given any currency format by default it
will consider it as $ -> {{ inputnumber | currency }}
{{ inputnumber | currency }}
- For indian rupees with no fractions : -> {{ inputnumber | currency:
'₹' : 0 }}
{{ inputnumber | currency : '₹' : 0}}
- For Euro with fractions :
{{ inputnumber | currency: '€' : inputfractions }}
{{ inputnumber | currency : '€' : inputfractions}}
Source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
.exmpul span
{
padding: 5px;
display: block;
background: #ccc;
margin: 10px 10px 20px 10px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
</head>
<body>
<div ng-app="SampleApp" ng-controller="SampleCntrl">
<ul class="exmpul">
<li>Input amount :
<input type="text" ng-model="inputnumber" />
</ul>
<ul class="exmpul">
<li>Default currency filter, if we have not given any currency format by default it
will consider it as $ -> <strong>{{ <em>inputnumber | currency</em> }}</strong>
<br />
<span>{{ inputnumber | currency }}</span> </li>
</ul>
<ul class="exmpul">
<li>For indian rupees with no fractions : -> <strong>{{ <em>inputnumber | currency:
'₹' : 0</em> }}</strong>
<br />
<span>{{ inputnumber | currency : '₹' : 0}}</span> </li>
</ul>
<ul class="exmpul">
<li>For Euro with fractions :
<input type="text" ng-model="inputfractions" />
<br />
<strong>{{ <em>inputnumber | currency: '€' : inputfractions</em> }}</strong>
<br />
<span>{{ inputnumber | currency : '€' : inputfractions}}</span> </li>
</ul>
</div>
<script>
var myapp = angular.module("SampleApp", []);
myapp.controller("SampleCntrl", function ($scope) {
$scope.inputnumber = 48643589.456542;
$scope.inputfractions = 3;
});
</script>
</body>
</html>
Useful Tools
Online Code Editor and Compiler
HTML Minifier
Online HTML Compiler/Preivew
Word Count Tool
Replace Text/Word tool
Latest Blogs
How to check if a canvas is empty or blank
Maintain div or panel scroll position after postback in asp.net update panel
Draggable button using jquery ui
Get total number of tables, views, stored procedures and functions count and names in sql server
JavaScript function to get date in mmddyyyy hhmmss ampm forma