How can I use an AngularJS filter to format a number to have leading zeros?

后端 未结 12 1755
挽巷
挽巷 2020-12-01 07:27

I checked the documentation. What I would like is for my numbers to have four digits and leading zeros.

22 to 0022
1  to 0001

Can someone

12条回答
  •  情歌与酒
    2020-12-01 07:54

    Pls use the below filter modify if required for some modifications

      app.filter('customNo', function () {
                return function (input) {
                    var n = input;
                    return (n < 10) ? '000' + n : (n < 100) ? '00' + n : (n < 1000) ? '0' + n : '' + n;
                }
            });
    
    
    {{number|customNo}}
    

提交回复
热议问题