INR currency format

2020-02-05 06:42发布

I need to show currency format like these, how can we show.

₹1
₹10
₹100
₹1,000
₹10,000
₹1,00,000
......

17条回答
Lonely孤独者°
2楼-- · 2020-02-05 07:26

You can make a filter using toLocaleString like :

Number(data).toLocaleString('en-IN', { style: 'currency', currency: 'INR', maximumFractionDigits: 0})

Filter example :

.filter('IndianCurrency', function() {
    return function(data) {
        if (null != data) {
            return Number(data).toLocaleString('en-IN', { style: 'currency', currency: 'INR', maximumFractionDigits: 0});
        } else {
            return Number(0).toLocaleString('en-IN', { style: 'currency',currency: 'INR', maximumFractionDigits: 0});
        }
    };
});

Usage :

{{ rent | IndianCurrency }}
查看更多
男人必须洒脱
3楼-- · 2020-02-05 07:26

In angular, Create a custom filter like this

myApp.filter('ic', function()
{
   return function(value)
   {
       return '₹ ' + value;
   }
});

And then you can {{data|number|ic}}

查看更多
你好瞎i
4楼-- · 2020-02-05 07:27
{{myobject.price | currency:'INR'}}

If you don't need last decimal value then you can use number pipe with

₹{{myobject.price | number}}

If you don't need last decimal value but you want to use the inbuilt currency pipe functionality, then you can create a custom pipe for currency or you can create a split pipe and use with currency

Ex: {{myobject.price  | currency:'INR' | custSplit:".":"0"}}

Note: custSplit- It is a custom pipe it split the string what ever we pass (here- ".") and take the index what we need(Here- "0"Index).

For more on pipe, read angular 2+ doc

查看更多
Luminary・发光体
5楼-- · 2020-02-05 07:36

Indian currency short like if you want to currency view like ₹ 2.5 Lakh, ₹ 3 Cr, ₹12 Lakh etc then use below Pipe. It will work

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'pricePipe'
})
export class PricePipePipe implements PipeTransform {

  transform(value: number, args: string[]): any {

    if (! isNaN(value)) {
        var currencySymbol = '₹';
        if (value == null) {
          return '';
      }
      var InrRSOut = value;
      InrRSOut = Math.round(InrRSOut);
      var RV = "";
      if (InrRSOut > 0 && InrRSOut < 1000) {
          RV = InrRSOut.toString();
      }
      else if (InrRSOut >= 1000 && InrRSOut < 10000) {
          RV = InrRSOut.toString();
      }
      else if (InrRSOut >= 10000 && InrRSOut < 100000) {
          var f1 = InrRSOut.toString().substring(0, 2);
          var f2 = InrRSOut.toString().substring(2, 5);
          RV = f1 + "," + f2;

      }
      else if (InrRSOut >= 100000 && InrRSOut < 1000000) {
          var f1 = InrRSOut.toString().substring(0, 1);
          var f2 = InrRSOut.toString().substring(1, 3);
          if (f2 == "00") {
              RV = f1 + " Lacs";
          }
          else {
              RV = f1 + "." + f2 + " Lacs";
          }
      }
      else if (InrRSOut >= 1000000 && InrRSOut < 10000000) {
          var f1 = InrRSOut.toString().substring(0, 2);
          var f2 = InrRSOut.toString().substring(2, 4);
          if (f2 == "00") {
              RV = f1 + " Lacs";
          }
          else {
              RV = f1 + "." + f2 + " Lacs";
          }
      }
      else if (InrRSOut >= 10000000 && InrRSOut < 100000000) {
          var f1 = InrRSOut.toString().substring(0, 1);
          var f2 = InrRSOut.toString().substring(1, 3);
          if (f2 == "00") {
              RV = f1 + " Cr";
          }
          else {
              RV = f1 + "." + f2 + " Cr";
          }
      }
      else if (InrRSOut >= 100000000 && InrRSOut < 1000000000) {
          var f1 = InrRSOut.toString().substring(0, 2);
          var f2 = InrRSOut.toString().substring(2, 4);
          if (f2 == "00") {
              RV = f1 + " Cr";
          }
          else {
              RV = f1 + "." + f2 + " Cr";
          }
      }
      else if (InrRSOut >= 1000000000 && InrRSOut < 10000000000) {
          var f1 = InrRSOut.toString().substring(0, 3);
          var f2 = InrRSOut.toString().substring(3, 5);
          if (f2 == "00") {
              RV = f1 + " Cr";
          }
          else {
              RV = f1 + "." + f2 + " Cr";
          }
      }
      else if (InrRSOut >= 10000000000) {
          var f1 = InrRSOut.toString().substring(0, 4);
          var f2 = InrRSOut.toString().substring(6, 8);
          if (f2 == "00") {
              RV = f1 + " Cr";
          }
          else {
              RV = f1 + "." + f2 + " Cr";
          }
      }
      else {
          RV = InrRSOut.toString();
      }
      return currencySymbol + RV;
    }

}

}

In HTML Use like

{{ 125000000 | pricePipe }}

Output

₹12.50 Cr
查看更多
疯言疯语
6楼-- · 2020-02-05 07:41

To print the rupee symbol(), try like this:

{{price | currency:"&#8377;"}}

For more formatting, refer this.

查看更多
家丑人穷心不美
7楼-- · 2020-02-05 07:41

Just add currency filter like this.

 {{object.price | currency:"INR":true}}
查看更多
登录 后发表回答