INR currency format

前端 未结 19 1701
栀梦
栀梦 2020-12-09 17:31

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

₹1
₹10
₹100
₹1,000
₹10,000
₹1,00,000
......
相关标签:
19条回答
  • 2020-12-09 17:51

    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
    
    0 讨论(0)
  • 2020-12-09 17:51

    Try this one

    var x=1000;
    x=x.toString();
    var lastThree = x.substring(x.length-3);
    var otherNumbers = x.substring(0,x.length-3);
    if(otherNumbers != '')
        lastThree = ',' + lastThree;
    var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
    
    alert(res);
    
    0 讨论(0)
  • 2020-12-09 17:52

    Just add currency filter like this.

     {{object.price | currency:"INR":true}}
    
    0 讨论(0)
  • 2020-12-09 17:54

    Just use INR in currency filter

    {{product.product_cost | currency:'INR':true}}
    
    0 讨论(0)
  • 2020-12-09 17:57

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

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

    For more formatting, refer this.

    0 讨论(0)
  • 2020-12-09 17:58

    You can format currency in INR with using pipe and even removing decimal value (i.e Paise) like

    {{bal.walletamt | currency:"₹ " : false : '2.0-0'}}
    

    this code will work for ionic3 also

    0 讨论(0)
提交回复
热议问题