MCPcopy Create free account
hub / github.com/angular/angular / padNumber

Function padNumber

packages/common/src/i18n/format_date.ts:285–309  ·  view source on GitHub ↗
(
  num: number,
  digits: number,
  minusSign = '-',
  trim?: boolean,
  negWrap?: boolean,
)

Source from the content-addressed store, hash-verified

283}
284
285function padNumber(
286 num: number,
287 digits: number,
288 minusSign = '-',
289 trim?: boolean,
290 negWrap?: boolean,
291): string {
292 let neg = '';
293 if (num < 0 || (negWrap && num <= 0)) {
294 if (negWrap) {
295 num = -num + 1;
296 } else {
297 num = -num;
298 neg = minusSign;
299 }
300 }
301 let strNum = String(num);
302 while (strNum.length < digits) {
303 strNum = '0' + strNum;
304 }
305 if (trim) {
306 strNum = strNum.slice(strNum.length - digits);
307 }
308 return neg + strNum;
309}
310
311function formatFractionalSeconds(milliseconds: number, digits: number): string {
312 const strMs = padNumber(milliseconds, 3);

Callers 5

formatFractionalSecondsFunction · 0.85
dateGetterFunction · 0.85
timeZoneGetterFunction · 0.85
weekGetterFunction · 0.85
weekNumberingYearGetterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected