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条回答
闹够了就滚
2楼-- · 2020-02-05 07:43

If any one looking same in angular 2 then here is solution , 1.Create custom pipe 2.Use in your html pipe code

1.Create custom pipe .

Create file indianCurrency.pipe.ts

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

@Pipe({name: 'indianCurrency'})
export class IndianCurrency implements PipeTransform {
  transform(value: number, args: string[]): any {

        if (! isNaN(value)) {
            var currencySymbol = '₹';
            //var output = Number(input).toLocaleString('en-IN');   <-- This method is not working fine in all browsers!           
            var result = value.toString().split('.');

            var lastThree = result[0].substring(result[0].length - 3);
            var otherNumbers = result[0].substring(0, result[0].length - 3);
            if (otherNumbers != '')
                lastThree = ',' + lastThree;
            var output = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;

            if (result.length > 1) {
                output += "." + result[1];
            }            

            return currencySymbol + output;
        }

  }
}

Declare in app.module.ts

 declarations: [
  .....,
    IndianCurrency
  ],

2.Use in your html

{{amount | indianCurrency}}
查看更多
Deceive 欺骗
3楼-- · 2020-02-05 07:43

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

查看更多
做个烂人
4楼-- · 2020-02-05 07:45

For display amount with two digits after decimal ...

Try this:

var num=1234.567;
 var ans= num.toLocaleString('en-IN',{ style: 'currency', currency: "INR",minimumFractionDigits:2,maximumFractionDigits:2 });

//output
//₹ 1,234.57
查看更多
祖国的老花朵
5楼-- · 2020-02-05 07:46

I know it's a bit late, but you can just use https://osrec.github.io/currencyFormatter.js/ which handles

Then all you need is:

// Outputs ₹ 25,34,234.00
OSREC.CurrencyFormatter.format(2534234, { currency: 'INR' }); 
查看更多
男人必须洒脱
6楼-- · 2020-02-05 07:47

Indian rupee follows different format compare to US currency; So, don't use default angular currency filter to format Indian Rupees

Custom INR Currency Filter

var app = angular.module('app', []);

app.controller('indexCtrl', function ($scope) {
    $scope.amount = 10000000.33;
});

app.filter('INR', function () {        
    return function (input) {
        if (! isNaN(input)) {
            var currencySymbol = '₹';
            //var output = Number(input).toLocaleString('en-IN');   <-- This method is not working fine in all browsers!           
            var result = input.toString().split('.');

            var lastThree = result[0].substring(result[0].length - 3);
            var otherNumbers = result[0].substring(0, result[0].length - 3);
            if (otherNumbers != '')
                lastThree = ',' + lastThree;
            var output = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
            
            if (result.length > 1) {
                output += "." + result[1];
            }            

            return currencySymbol + output;
        }
    }
});
<!DOCTYPE html>
<html ng-app="app">
<head>    
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="indexCtrl">
    Input: <input type="text" ng-model="amount">
    <h3>{{amount | INR}}</h3>
</body>
</html>

查看更多
登录 后发表回答