二手车交易,行驶公里保留一位小数

This commit is contained in:
2025-03-19 18:00:01 +08:00
parent 48ab0cfb52
commit db6a3facae
2 changed files with 6 additions and 6 deletions

View File

@ -152,11 +152,11 @@ export default {
}, },
methods:{ methods:{
formatToWan(num) { formatToWan(num) {
let result = (num / 10000).toString(); let result = (num / 10000).toString(); // 转换为万单位
if (result.includes('.')) { if (result.includes('.')) {
let decimalPart = result.split('.')[1]; let decimalPart = result.split('.')[1]; // 获取小数部分
if (decimalPart.length > 2) { if (decimalPart.length > 1) {
result = parseFloat(result).toFixed(2); result = parseFloat(result).toFixed(1); // 保留一位小数
} }
} }
return result + '万'; return result + '万';

View File

@ -196,8 +196,8 @@ export default {
let result = (num / 10000).toString(); let result = (num / 10000).toString();
if (result.includes('.')) { if (result.includes('.')) {
let decimalPart = result.split('.')[1]; let decimalPart = result.split('.')[1];
if (decimalPart.length > 2) { if (decimalPart.length > 1) {
result = parseFloat(result).toFixed(2); result = parseFloat(result).toFixed(1);
} }
} }
return result + '万'; return result + '万';