Skip to content

Commit e94e3fb

Browse files
authored
NumberInput - fix floating point error (#2877)
1 parent 295b5ee commit e94e3fb

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/components/numberInput/Presenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function factor(options: Options): number {
5050
}
5151

5252
export function getInitialNumber(propsInitialNumber = 0, options: Options) {
53-
return propsInitialNumber * factor(options);
53+
return Number((propsInitialNumber * factor(options)).toFixed(0));
5454
}
5555

5656
export function parseInput(text: string, options: Options, initialNumber?: number): NumberInputData {

src/components/numberInput/__tests__/Presenter.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ describe('NumberInput', () => {
3939
it('should return 10 for 1 if fractionDigits is 1', () => {
4040
expect(getInitialNumber(1, {...EN_OPTIONS, fractionDigits: 1})).toEqual(10);
4141
});
42+
43+
it('Handle wrong result with some X.XX numbers', () => {
44+
expect(getInitialNumber(8.97, {...EN_OPTIONS})).toEqual(897);
45+
});
4246
});
4347

4448
describe('getInitialData', () => {

0 commit comments

Comments
 (0)