Showing
1 changed file
with
6 additions
and
3 deletions
| ... | ... | @@ -91,11 +91,14 @@ |
| 91 | 91 | }; |
| 92 | 92 | |
| 93 | 93 | // 获取小数 |
| 94 | - const getFloatPart = (number): any => { | |
| 94 | + const getFloatPart = (number: string | number) => { | |
| 95 | + const isLessZero = Number(number) < 0; | |
| 95 | 96 | number = number.toString(); |
| 96 | 97 | const floatPartStartIndex = number.indexOf('.'); |
| 97 | - const value = ~floatPartStartIndex ? `0.${number.substring(floatPartStartIndex + 1)}` : '0'; | |
| 98 | - return value; | |
| 98 | + const value = ~floatPartStartIndex | |
| 99 | + ? `${isLessZero ? '-' : ''}0.${number.substring(floatPartStartIndex + 1)}` | |
| 100 | + : '0'; | |
| 101 | + return Number(value); | |
| 99 | 102 | }; |
| 100 | 103 | |
| 101 | 104 | const { createMessage } = useMessage(); | ... | ... |