Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a number in Indian format using angular 2

I want to print numbers with commas as thousands, lacs, crores separators. for e.g:

     10,000 - ten thousand
   1,00,000 - 1 lakh
  10,00,000 - 10 lakh
1,00,00,000 - 1 crore

I have used angular's number pipe to implement comma separated values but not getting proper output it displays like this 1,000,000 - 10 lakh.

How can i implement above functionality using angular/javascript or is there any pipe for this in angular?

like image 373
lakhan Avatar asked Dec 20 '18 04:12

lakhan


People also ask

How to display currency in angular?

Angular Currency Pipe without symbol If you want to display your own name instead of default currency symbol you have to pass display parameter. The display parameter can be “code” (currencycode will be displayed) or “symbol” or “symbol-narrow” or any other custom value.

How to remove decimal in currency Pipe angular?

If you don't need the decimal you can use the number pipe. The currency pipe is for formatting your numbers so you could use: {{2.56 | currency : 'USD' : 'symbol' : '1.0-0'}} but this will round your number up.

What is the use of Currencypipe in angular?

Transforms a number to a currency string, formatted according to locale rules that determine group sizing and separator, decimal-point character, and other locale-specific configurations.


1 Answers

You can use .toLocalString()

The toLocaleString() method returns a string with a language-sensitive representation of this number.

var tenK= 10000;
var oneL = 100000;
var tenL = 1000000;
var oneCr = 10000000;
console.log(tenK.toLocaleString('en-IN'));
console.log(oneL.toLocaleString('en-IN'));
console.log(tenL.toLocaleString('en-IN'));
console.log(oneCr.toLocaleString('en-IN'));
like image 60
Prasad Telkikar Avatar answered Sep 28 '22 16:09

Prasad Telkikar