How to add thousand separating commas for numbers in angularJS?

Vedant Nighojkar picture Vedant Nighojkar · Mar 18, 2016 · Viewed 29.7k times · Source

I simply want to convert a string of numbers to a number which will be displayed using thousand separated commas.

var value = "123456";

I want to display "123,465" in a grid. I have looked some documentation on this but everything is about displaying it in HTML. I want to display this in a dynamic grid.

function numberRenderer (params) {
                    return new Number (params.value);
                }

I want to format the number so that I can convert that into a string for display.

Answer

jbrown picture jbrown · Mar 18, 2016

Use a filter ...

HTML usage

{{ number_expression | number : fractionSize}}

Js usage

$filter('number')(number, fractionSize)