Angular2 or TypeScript Left padding a String with Zeros

后端 未结 7 1825
無奈伤痛
無奈伤痛 2020-12-16 09:42

I have a number let say 9. But I need it as String \"09\".

I know i can write my own logic. But I am looking for a implicit util function which can pad it.

I

7条回答
  •  渐次进展
    2020-12-16 10:22

    Since Angular v4 there is DecimalPipe which let's easily add leading zeros: https://angular.io/api/common/DecimalPipe

    In your html, you can use then something like:

    {{ myNumber | number:'2.0' }}

提交回复
热议问题