@ni/nimble-components 20.2.3 → 20.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,8 @@ import { NumberFormatter } from './number-formatter';
4
4
  */
5
5
  export declare class DecimalFormatter extends NumberFormatter {
6
6
  private readonly formatter;
7
+ private readonly tenPowDecimalDigits;
7
8
  constructor(decimalsToDisplay: number);
8
9
  protected format(number: number): string;
10
+ private willRoundToZero;
9
11
  }
@@ -4,6 +4,8 @@ import { NumberFormatter } from './number-formatter';
4
4
  */
5
5
  export declare class DecimalFormatter extends NumberFormatter {
6
6
  private readonly formatter;
7
+ private readonly tenPowDecimalDigits;
7
8
  constructor(decimalsToDisplay: number);
8
9
  protected format(number: number): string;
10
+ private willRoundToZero;
9
11
  }
@@ -10,12 +10,18 @@ export class DecimalFormatter extends NumberFormatter {
10
10
  minimumFractionDigits: decimalsToDisplay,
11
11
  useGrouping: true
12
12
  });
13
+ this.tenPowDecimalDigits = 10 ** decimalsToDisplay;
13
14
  }
14
15
  format(number) {
15
16
  // The NumberFormat option of `signDisplay: "negative"` is not supported in all browsers nimble supports.
16
17
  // Because that option cannot be used to avoid rendering "-0", coerce the value -0 to 0 prior to formatting.
17
- const valueToFormat = number === 0 ? 0 : number;
18
+ const valueToFormat = this.willRoundToZero(number) ? 0 : number;
18
19
  return this.formatter.format(valueToFormat);
19
20
  }
21
+ willRoundToZero(number) {
22
+ // Multiply the value by 10 raised to decimal-digits so that Math.round can be used to emulate rounding to
23
+ // decimal-digits decimal places. If that rounded value is 0, then the value will be rendered with only 0s.
24
+ return Math.round(number * this.tenPowDecimalDigits) === 0;
25
+ }
20
26
  }
21
27
  //# sourceMappingURL=decimal-formatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decimal-formatter.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/models/decimal-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IAGjD,YAAmB,iBAAyB;QACxC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE;YAC9C,qBAAqB,EAAE,iBAAiB;YACxC,qBAAqB,EAAE,iBAAiB;YACxC,WAAW,EAAE,IAAI;SACpB,CAAC,CAAC;IACP,CAAC;IAES,MAAM,CAAC,MAAc;QAC3B,yGAAyG;QACzG,4GAA4G;QAC5G,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAChD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAChD,CAAC;CACJ"}
1
+ {"version":3,"file":"decimal-formatter.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/models/decimal-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IAIjD,YAAmB,iBAAyB;QACxC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE;YAC9C,qBAAqB,EAAE,iBAAiB;YACxC,qBAAqB,EAAE,iBAAiB;YACxC,WAAW,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,mBAAmB,GAAG,EAAE,IAAI,iBAAiB,CAAC;IACvD,CAAC;IAES,MAAM,CAAC,MAAc;QAC3B,yGAAyG;QACzG,4GAA4G;QAC5G,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAChE,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAChD,CAAC;IAEO,eAAe,CAAC,MAAc;QAClC,0GAA0G;QAC1G,2GAA2G;QAC3G,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ni/nimble-components",
3
- "version": "20.2.3",
3
+ "version": "20.2.4",
4
4
  "description": "Styled web components for the NI Nimble Design System",
5
5
  "scripts": {
6
6
  "build": "npm run generate-icons && npm run build-components && npm run bundle-components && npm run generate-scss && npm run build-storybook",