diff --git a/packages/core/src/components/forms/numericInputUtils.ts b/packages/core/src/components/forms/numericInputUtils.ts index 5c4cbf98cc..ee128b02b4 100644 --- a/packages/core/src/components/forms/numericInputUtils.ts +++ b/packages/core/src/components/forms/numericInputUtils.ts @@ -30,7 +30,8 @@ function getDecimalSeparator(locale: string) { } export function toLocaleString(num: number, locale: string = "en-US") { - return sanitizeNumericInput(num.toLocaleString(locale), locale); + // HACKHACK: roundingPriority is not supported yet in TypeScript https://github.com/microsoft/TypeScript/issues/43336 + return sanitizeNumericInput(num.toLocaleString(locale, { roundingPriority: "morePrecision" } as any), locale); } export function clampValue(value: number, min?: number, max?: number) { diff --git a/packages/core/test/controls/numericInputTests.tsx b/packages/core/test/controls/numericInputTests.tsx index 7368b068fc..b4ed0a2f23 100644 --- a/packages/core/test/controls/numericInputTests.tsx +++ b/packages/core/test/controls/numericInputTests.tsx @@ -1103,6 +1103,21 @@ describe("", () => { expect(component.find("input").prop("value")).to.equal("1.001"); }); + it("handle big decimal numbers", () => { + const onValueChangeSpy = spy(); + const component = mount( + , + ); + const input = component.find("input"); + input.simulate("keydown", { key: "ArrowUp" }); + assert.isTrue(onValueChangeSpy.calledWith(0.000000000000000001)); + }); + it("changes max precision appropriately when the min/max stepSize props change", () => { const onValueChangeSpy = spy(); const component = mount(