{"id":3779,"date":"2018-07-03T12:38:30","date_gmt":"2018-07-03T07:08:30","guid":{"rendered":"https:\/\/code4developers.com\/?p=3779"},"modified":"2018-08-19T20:36:50","modified_gmt":"2018-08-19T15:06:50","slug":"currencypipe-percentpipe","status":"publish","type":"post","link":"https:\/\/code4developers.com\/currencypipe-percentpipe\/","title":{"rendered":"Pipes in Angular Part \u2013 3 : CurrencyPipe, PercentPipe"},"content":{"rendered":"<p>Here is the third installment of angular pipe series in this part we will discuss about CurrencyPipe, and PercentPipe, If you have not read previous articles here is the link for previous articles.<\/p>\n<p><!--more--><\/p>\n<div>\n<ul>\n<li><a href=\"https:\/\/code4developers.com\/angular-pipes\/\">Pipes in Angular Part \u2013 1 : lowercase, uppercase, and titlecase pipes<\/a><\/li>\n<li>\n<div>\n<div><a href=\"https:\/\/code4developers.com\/datepipe-in-angular\/\">Pipes in Angular Part \u2013 2 : DatePipe<\/a><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<p>CurrencyPipe, and PercentPipe, Both are used to transform a number to a specific type of currency, and percentage value.<\/p>\n<h3 id=\"currencypipe\">CurrencyPipe<\/h3>\n<p>CurrencyPipe is used to transform a number to a currency string according to the locale rule.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<div>\n<div>{{ value_expression | currency [ : currencyCode [ : display [ : digitsInfo [ : locale ] ] ] ] }}<\/div>\n<\/div>\n<div><\/div>\n<div>Consider the below code to apply currencyPipe and which we will use in our demos.<\/div>\n<div><\/div>\n<div><strong>app.component.ts<\/strong><\/div>\n<div>\n<pre class=\"theme:github lang:default decode:true\">import { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: ['.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  amount: number = 20120;\r\n}\r\n<\/pre>\n<p><strong>app.component.html<\/strong><\/p>\n<pre class=\"theme:github lang:default decode:true\">&lt;div style=\"text-align:left\"&gt;\r\n  &lt;p&gt;Amount is : {{amount | currency}}\r\n&lt;\/div&gt;\r\n\r\n\/\/Output: Amount is : $20,120.00<\/pre>\n<p>This is the way by which we can apply currencypipe. Now let us discuss and apply all the parameters to format currency in more ways.<\/p>\n<h4 id=\"currencycode\"><strong>currencyCode <\/strong><\/h4>\n<p>{{ value_expression | currency [ : <strong>currencyCode<\/strong> [ : display [ : digitsInfo [ : locale ] ] ] ] }}<\/p>\n<ul>\n<li>The currencyCode such as <strong>INR<\/strong> for Indian Rupee , <strong>USD<\/strong> for US dollar, <strong>EUR<\/strong> for the euro<\/li>\n<li>Default it is <strong>undefined<\/strong><\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/ISO_4217\" target=\"_blank\" rel=\"noopener\">Check this out for full list of currency code <\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">&lt;div style=\"text-align:left\"&gt;\r\n  &lt;p&gt;Amount is : {{amount | currency : 'INR'}}\r\n&lt;\/div&gt;\r\n\r\n\/\/Output: Amount is : \u20b920,120.00<\/pre>\n<h4 id=\"display\"><strong>display<\/strong><\/h4>\n<p>{{ value_expression | currency [ : currencyCode [ : <strong>display<\/strong> [ : digitsInfo [ : locale ] ] ] ] }}<\/p>\n<p>This is used to display the format of the currency indicator. It has certain values listed in below table. But before that let us see how to use one of them<\/p>\n<pre class=\"theme:github lang:default decode:true\">&lt;div style=\"text-align:left\"&gt;\r\n  &lt;p&gt;Amount is : {{amount | currency : 'INR' : 'code'}}\r\n&lt;\/div&gt;\r\n\r\n\/\/Output: Amount is : INR20,120.00<\/pre>\n<p>Here, in output we can see &#8216;INR&#8217; instead of rupee symbol.\u00a0 So here is the full table for display values.<\/p>\n[table style=&#8221;3&#8243;]\n[tr][th]value[\/th] [th]Description[\/th] [th]Output[\/th][\/tr]\n[tr][td]code[\/td] [td]It will show the code like <strong>INR<\/strong>[\/td] [td]Amount is : INR20,120.00[\/td][\/tr]\n[tr][td]symbol[\/td] [td]This is default, and it will show symbol like <strong>\u20b9<\/strong>[\/td] [td]Amount is : \u20b920,120.00 [\/td][\/tr]\n[tr][td]symbol-narrow[\/td] [td]Use this for locales that have two symbols for their currency. For example, the Canadian dollar CAD has the symbol CA$ and the symbol-narrow $. If the locale has no narrow symbol, uses the standard symbol for the locale[\/td][td]<code>Amount is : {{amount | currency : 'CAD' : 'symbol-narrow'}}<\/code><\/p>\n<p>Amount is : $20,120.00[\/td][\/tr]\n[tr][td]string[\/td] [td]This is used to display a given string instead of any code or symbol[\/td] [td]<code>Amount is : {{amount | currency : 'hello'}} \/\/Output:Amount is : hello20,120.00<\/code>[\/td][\/tr]\n<\/div>\n<div>\n[\/table]\n<h4 id=\"digitsinfo\"><strong>digitsInfo<\/strong><\/h4>\n<p>{{ value_expression | currency [ : currencyCode [ : display [ : <strong>digitsInfo<\/strong> [ : locale ] ] ] ] }}<\/p>\n<p>Decimal representation options, specified by a string in the following format: <strong>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}<\/strong><\/p>\n<p>Let us consider a below code to understand uses. For that we need to change value of amount.<br \/>\n<strong><code>amount: number = 0.12;<\/code><\/strong><\/p>\n<p><img  loading=\"lazy\"  decoding=\"async\"  data-attachment-id=\"3797\"  data-permalink=\"https:\/\/code4developers.com\/currencypipe-percentpipe\/digitsinfo\/\"  data-orig-file=\"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?fit=1246%2C422&amp;ssl=1\"  data-orig-size=\"1246,422\"  data-comments-opened=\"1\"  data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\"  data-image-title=\"digitsInfo\"  data-image-description=\"\"  data-image-caption=\"\"  data-medium-file=\"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?fit=800%2C271&amp;ssl=1\"  data-large-file=\"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?fit=1160%2C393&amp;ssl=1\"  class=\"alignnone wp-image-3797 pk-lazyload\"  src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAP+KeNJXAAAAAXRSTlMAQObYZgAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\"  alt=\"CurrencyPipe\"  width=\"600\"  height=\"203\"  data-pk-sizes=\"auto\"  data-ls-sizes=\"auto, (max-width: 600px) 100vw, 600px\"  data-pk-src=\"https:\/\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png\"  data-pk-srcset=\"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?w=1246&amp;ssl=1 1246w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=800%2C271&amp;ssl=1 800w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=1160%2C393&amp;ssl=1 1160w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=120%2C41&amp;ssl=1 120w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=90%2C30&amp;ssl=1 90w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=320%2C108&amp;ssl=1 320w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=560%2C190&amp;ssl=1 560w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=240%2C81&amp;ssl=1 240w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=180%2C61&amp;ssl=1 180w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=640%2C217&amp;ssl=1 640w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=1120%2C379&amp;ssl=1 1120w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=300%2C102&amp;ssl=1 300w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=768%2C260&amp;ssl=1 768w, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/07\/digitsInfo.png?resize=700%2C237&amp;ssl=1 700w\" ><\/p>\n<ul>\n<li><strong>minIntegerDigits<\/strong>: The minimum number of integer digits before the decimal point. Default is 1.<\/li>\n<li><strong>minFractionDigits<\/strong>: The minimum number of digits after the decimal point. Default is 0.<\/li>\n<li><strong>maxFractionDigits<\/strong>: The maximum number of digits after the decimal point. Default is 3.<\/li>\n<\/ul>\n<h4 id=\"locale\"><strong>locale<\/strong><\/h4>\n<p>{{ value_expression | currency [ : currencyCode [ : display [ : digitsInfo [ : <strong>locale<\/strong> ] ] ] ] }}<\/p>\n<p>A locale code for the locale format rules to use. When not supplied, uses the value of LOCALE_ID, which is en-US by default.<\/p>\n<p>Optional. Default is undefined.<\/p>\n<\/div>\n<h3 id=\"percentpipe\">PercentPipe<\/h3>\n<p>It is used to transform a number to a percentage string according to a locale rules.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<div>\n<div>{{ value_expression | percent [ : digitsInfo [ : locale ] ] }}<\/div>\n<\/div>\n<div><\/div>\n<div>Consider the below code for the usage<\/div>\n<div><\/div>\n<div><strong>app.component.ts<\/strong><\/div>\n<div>\n<pre class=\"theme:github lang:default decode:true\">import { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: ['.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  num1: number = 0.12;\r\n}\r\n<\/pre>\n<p><strong>app.component.html<\/strong><\/p>\n<pre class=\"theme:github lang:default decode:true\">&lt;div style=\"text-align:left\"&gt;\r\n  &lt;p&gt;Percentage is : {{num1 | percent}}\r\n&lt;\/div&gt;\r\n\r\n\/\/Output: Percentage is : 12%<\/pre>\n<p>There are two parameters which we can pass with the percentPipe,<\/p>\n<p>1. digitsInfo<\/p>\n<p>2. locale.<\/p>\n<p>This both parameter works same as currencyPipe. Consider that description for the same, and let us see a small example by passing <strong>digitsInfo <\/strong>parameter in above example and see the output<\/p>\n<pre class=\"lang:default decode:true\">&lt;div style=\"text-align:left\"&gt;\r\n  &lt;p&gt;Percentage is : {{num1 | percent : '2.2-2'}}\r\n&lt;\/div&gt;\r\n\r\n\/\/Output: Percentage is : 12.00%<\/pre>\n<h3 id=\"summary\">Summary<\/h3>\n<p>In this article we have discussed how to use currency, and percent pipe to format a number. In next article we will have a look on <a href=\"https:\/\/code4developers.com\/slicepipe-jsonpipe-asyncpipe\/#SlicePipe\">SlicePipe<\/a>, <a href=\"https:\/\/code4developers.com\/slicepipe-jsonpipe-asyncpipe\/#JSONPipe\">JSON Pipe<\/a> and <a href=\"https:\/\/code4developers.com\/slicepipe-jsonpipe-asyncpipe\/#AsyncPipe\">Async Pipe<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here is the third installment of angular pipe series in this part we will discuss about CurrencyPipe, and PercentPipe, If you have not read previous articles here is the link&hellip;<\/p>\n","protected":false},"author":4,"featured_media":2649,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[29,197,173,179,194,206,200,201,202,205,204,203,199],"powerkit_post_featured":[],"class_list":{"0":"post-3779","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-angular","8":"tag-angular","9":"tag-angular-4","10":"tag-angular-5","11":"tag-angular-6","12":"tag-angular-pipes","13":"tag-currencycode","14":"tag-currencypipe","15":"tag-digitsinfo","16":"tag-locale","17":"tag-maxfractiondigits","18":"tag-minfractiondigits","19":"tag-minintegerdigits","20":"tag-percentpipe"},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/angular-2.png?fit=240%2C240&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8NAi4-YX","jetpack-related-posts":[{"id":4091,"url":"https:\/\/code4developers.com\/create-custom-pipes-aka-filters-in-angular-2-x\/","url_meta":{"origin":3779,"position":0},"title":"Create Custom Pipes &#8211; Filters in Angular 2.X +","author":"Arif Khoja","date":"March 10, 2019","format":false,"excerpt":"Our applications may have a lot of data for presentation, But for creating a good user experience it is preferable to see in a more understandable format like March 12, 2010 is better to read then Mon Mar 12 2010 15:23:40 GMT-0700 (Pacific Daylight Time). For such small and repeated\u2026","rel":"","context":"In &quot;Angular&quot;","block_context":{"text":"Angular","link":"https:\/\/code4developers.com\/category\/angular\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/angular-2.png?fit=240%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3746,"url":"https:\/\/code4developers.com\/angular-pipes\/","url_meta":{"origin":3779,"position":1},"title":"Pipes in Angular Part &#8211; 1 : lowercase, uppercase, and titlecase pipes","author":"Yatendrasinh Joddha","date":"June 30, 2018","format":false,"excerpt":"In this series of article for the angular rookies we will discuss about pipes in Angular, a way to write display-value transformations that you can declare in your HTML. In this article we will discuss about lowercase, uppercase, and titlecase pipes. At the end of the series we will create\u2026","rel":"","context":"In &quot;Angular&quot;","block_context":{"text":"Angular","link":"https:\/\/code4developers.com\/category\/angular\/"},"img":{"alt_text":"example output","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/06\/example-output.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3818,"url":"https:\/\/code4developers.com\/slicepipe-jsonpipe-asyncpipe\/","url_meta":{"origin":3779,"position":2},"title":"Pipes in Angular Part \u2013 4 : SlicePipe, JSONPipe, AsyncPipe","author":"Yatendrasinh Joddha","date":"August 19, 2018","format":false,"excerpt":"Here is the fourth part of angular pipe series in this part we will discuss about SlicePipe, JSONPipe, and AsyncPipe. If you have not read previous articles here is the link for previous articles. Pipes in Angular Part \u2013 1 : lowercase, uppercase, and titlecase pipes Pipes in Angular Part\u2026","rel":"","context":"In &quot;Angular&quot;","block_context":{"text":"Angular","link":"https:\/\/code4developers.com\/category\/angular\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/angular-2.png?fit=240%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2625,"url":"https:\/\/code4developers.com\/angular-4-project-structure\/","url_meta":{"origin":3779,"position":3},"title":"Angular 4 Project Structure","author":"Nisarg Dave","date":"June 18, 2017","format":false,"excerpt":"Introduction In previous article we learned about Angular 4 Installation. You can find that article on https:\/\/code4developers.com\/angular-4-installations\/\u00a0. This article describes the project structure of Angular 4 application which Angular CLI created for us. I have already created ANGULAR4DEMO project in my previous article, so we will use that project to\u2026","rel":"","context":"In &quot;Angular&quot;","block_context":{"text":"Angular","link":"https:\/\/code4developers.com\/category\/angular\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/1-1.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3340,"url":"https:\/\/code4developers.com\/top-angularjs-interview-question\/","url_meta":{"origin":3779,"position":4},"title":"Top AngularJS interview questions","author":"Arif Khoja","date":"March 23, 2018","format":false,"excerpt":"Read Angular js interview questions including topic advanced topics like Dependency injection, Two-way binding, scope in angular js and many more. 1.Explain Directive scopes? There are three types of directive scopes available in Angular. Parent Scope: is default scope Child Scope: If the properties and functions you set on the\u2026","rel":"","context":"In &quot;AngularJs&quot;","block_context":{"text":"AngularJs","link":"https:\/\/code4developers.com\/category\/angularjs\/"},"img":{"alt_text":"AngularJs LOGO","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/angular.png?fit=500%2C500&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2586,"url":"https:\/\/code4developers.com\/angular-4-installations\/","url_meta":{"origin":3779,"position":5},"title":"Angular 4 Installations","author":"Nisarg Dave","date":"June 14, 2017","format":false,"excerpt":"Introduction This article demonstrates how to install Angular 4 in your local system and start working with angular\/cli using basic commands. What is Angular 4? Before starting with Angular 4, we need to know about Angular 2. Angular 2 is totally different kind of framework from Angular 1. Angular 1\u2026","rel":"","context":"In &quot;Angular&quot;","block_context":{"text":"Angular","link":"https:\/\/code4developers.com\/category\/angular\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/1.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/1.png?resize=700%2C400 2x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/06\/1.png?resize=1050%2C600 3x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts\/3779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/comments?post=3779"}],"version-history":[{"count":20,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts\/3779\/revisions"}],"predecessor-version":[{"id":3879,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts\/3779\/revisions\/3879"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/media\/2649"}],"wp:attachment":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/media?parent=3779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/categories?post=3779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/tags?post=3779"},{"taxonomy":"powerkit_post_featured","embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/powerkit_post_featured?post=3779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}