Search code examples
angularjsformattingcurrencyeuro

How to format currency like kendo ui 's template using angularjs


I want to get this format In USD : 1.123.362,32 and this format in euro :1,122,363.33 I used AngularJS Filter "currency" who Format a number to a currency format but without separtors like "," "."


Solution

  • Use a Filter

    here is a link to the docs where you can see an example.

    You need to use the currency filter to get the desired effect. It should look like this

    HTML

    {{ currency_expression | currency : symbol : fractionSize}}
    

    JS

    $filter('currency')(amount, symbol, fractionSize)
    

    To do this with the correct , or . you need to have the correct currency format selected.

    Math.round()

    inside your controller when you are setting the scope make sure you do Math.round() so the number you return is always whole.

    Example

    Math.round(2.5);
    

    Alternatively

    If the currency filter does not meet your requirements you can always use the number format that Angular provides, Doc are here

    HTML

    {{ number_expression | number : fractionSize}}
    

    JS

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

    If All Else Fails

    Create your own custom filter here is a tutorial on how to build your own custom filter in angular, since your requirements are a little strange you should consider building your own filter to match them. This way you can set your , or . and anything that precedes or follows your number.

    Its definitely more difficult than using the built in functionality but since you cant get it to match up with either of the methods above I would take this route.