Search code examples
angularjsnumber-formatting

How to add thousand separating commas for numbers in angularJS?


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.


Solution

  • Use a filter ...

    HTML usage

    {{ number_expression | number : fractionSize}}
    

    Js usage

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