Skip to content

Commit b5fa25a

Browse files
authored
fix: negative number should support round (#383)
1 parent 7440f52 commit b5fa25a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/utils/MiniDecimal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function toFixed(numStr: string, separatorStr: string, precision?: number
282282

283283
if (advancedNum >= 5) {
284284
const advancedDecimal = getMiniDecimal(numStr).add(
285-
`0.${'0'.repeat(precision)}${10 - advancedNum}`,
285+
`${negativeStr}0.${'0'.repeat(precision)}${10 - advancedNum}`,
286286
);
287287
return toFixed(advancedDecimal.toString(), separatorStr, precision);
288288
}

tests/util.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,10 @@ describe('InputNumber.Util', () => {
145145
it('should return "" when input is ""', () => {
146146
expect(toFixed('', '.')).toEqual('');
147147
});
148+
149+
it('negative', () => {
150+
// expect(toFixed('77.88', '.', 1)).toEqual('77.9');
151+
expect(toFixed('-77.88', '.', 1)).toEqual('-77.9');
152+
});
148153
});
149154
});

0 commit comments

Comments
 (0)