|
@@ -84,17 +84,12 @@ const CostComparison = (props) => {
|
|
|
// 大于100,保留一位
|
|
|
// 大于1000,不保留
|
|
|
let fixed = 0;
|
|
|
+ if (maxValue === 0) return fixed;
|
|
|
if (maxValue < 1) {
|
|
|
- const decimal = maxValue.toFixed(100).toString().split('.')[1];
|
|
|
- const decimalArr = decimal.split('');
|
|
|
- for (let index = 0; index < decimalArr.length; index++) {
|
|
|
- if (decimalArr[index] === '0') {
|
|
|
- fixed++;
|
|
|
- } else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- fixed += 2;
|
|
|
+ //maxValue + 1 防止maxValue过小自动转科学计数法
|
|
|
+ const decimal = (maxValue + 1).toString().split('.')[1];
|
|
|
+ const num = decimal.split('').findIndex((num) => num > 0);
|
|
|
+ fixed = num + 3;
|
|
|
} else if (maxValue < 10) {
|
|
|
fixed = 3;
|
|
|
} else if (maxValue < 100) {
|