I need to show currency format like these, how can we show.
₹1
₹10
₹100
₹1,000
₹10,000
₹1,00,000
......
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
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);
Just add currency filter like this.
{{object.price | currency:"INR":true}}
Just use INR in currency filter
{{product.product_cost | currency:'INR':true}}
To print the rupee symbol(₹), try like this:
{{price | currency:"₹"}}
For more formatting, refer this.
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