Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Formatting currency using Angular

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 500
    Comment on it

    Hi all,

    Here is an example how to format currency using Angular filters.

    Formats a number as a currency (ie $1,234.56). When no currency symbol is provided, default symbol for current locale is used. - AngularJS

    HTML:-

    <body ng-controller="CountryCtrl">
            <table>
              <tr>
                <th>Country</th>
                <th>Population</th>
                <th>Flag</th>
                <th>Capital</th>
                <th>GDP (PPP)</th>
              </tr>
              <tr ng-repeat="country in countries">
                <td>{{country.name}}</td>
                <td>{{country.population}}</td>
                <td><img ng-src="{{country.flagURL}}" width="100"></td>
                <td>{{country.capital}}</td>
                <td>{{country.gdp | currency : "$"}}</td>
              </tr>
            </table>
          </body>
    

    Script:-

    <script>
      var countryApp = angular.module('countryApp', []);
      countryApp.controller('CountryCtrl', function ($scope, $http){
        $http.get('countries.json').success(function(data) {
          $scope.countries = data;
        });
      });
    </script>
    

    Json :-

    [
      {
        "name": "China",
        "population": 1359821000,
        "flagURL": "http://upload.wikimedia.org/wikipedia/commons/f/fa/Flag_of_the_People%27s_Republic_of_China.svg",
        "capital": "Beijing",
        "gdp": 12261
      },
      {
        "name": "India",
        "population": 1205625000,
        "flagURL": "http://upload.wikimedia.org/wikipedia/en/4/41/Flag_of_India.svg",
        "capital": "New Delhi",
        "gdp": 4716
      },
      {
        "name": "United States of America",
        "population": 312247000,
        "flagURL": "http://upload.wikimedia.org/wikipedia/en/a/a4/Flag_of_the_United_States.svg",
        "capital": "Washington, D.C.",
        "gdp": 16244
      }
    ]
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: