Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: Formatting numbers with commas

Title very much sums up my needs.

123456789 => 123,456,789 12345 => 12,345 

What's the best way to get this conversion ? Don't suggest currency pipe in Angular-2 as I don't need $ or currency symbol to be prepend to my output.

like image 502
BeingSuman Avatar asked Jul 05 '17 14:07

BeingSuman


Video Answer


2 Answers

Use DecimalPipe like this

{{attr | number}}

Working Plunker

Documentation available at https://angular.io/api/common/DecimalPipe

like image 123
CodeWarrior Avatar answered Oct 02 '22 15:10

CodeWarrior


function printNo() {    document.getElementById('text').innerHTML =    Number(1234355).toLocaleString('en-GB');  }
 <!DOCTYPE html>   <html>      <head></head>             <body onload="printNo()">        <h1 id="text"></h1>                 </body>  </html>

Reference link

like image 44
JGFMK Avatar answered Oct 02 '22 14:10

JGFMK