Sunday, June 15, 2014

How to use AngularJS currency filter?


currency filter

Code:

<!DOCTYPE html>

<html>
<head>
<title>Using AngularJS Currency Filter</title>
</head>
<body ng-app="">

       <div>
              Enter Amount:
              <input type="number" ng-model="amount" ng-init="amount='1234567890'">
              <br>
              default currency symbol ($): {{amount | currency}}
              <br>
              custom currency identifier (€): {{amount | currency:"€"}}
       </div>

       <script src="angular.js"></script>
</body>
</html>

Output:


Enter Amount:
default currency symbol ($): {{currencyAmount| currency}}
custom currency identifier (€): {{currencyAmount| currency:"€"}}
  • Formats a number as a currency (i.e. $1,234.56)
  • Usage: {{ currency_expression | currency : symbol}}
  • In the above example, amount represents the currency_expression which is the value to be represented as a currency amount. The value is formatted to 2 decimal places.
  • currency is the filter keyword
  • "€" is a symbol which is an optional argument. It could be any currency symbols or identifiers.
  • When no currency symbol is provided, default symbol for current locale is used.


No comments :

Post a Comment