angular.js - wrapping the currency symbol and decimal numbers in spans

后端 未结 3 2171
遥遥无期
遥遥无期 2021-02-13 21:35

Can you possibly do something like this in angular?

\"enter

It\'s not quite possib

3条回答
  •  醉话见心
    2021-02-13 22:11

    You can create a custom filter

    app.filter('euro', function () {
        return function (text) {
            text = text.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1 ");
            var t = text + ',00';
            return t;
        };
    });
    
    
    

    The result will be

    1 000 000,00€
    

    Working Demo

    (The regex is posted by @Paul Creasey in his answer https://stackoverflow.com/a/1990554/304319)

提交回复
热议问题