Skip to content

Commit

Permalink
修正生成物编只能保留一位小数的bug
Browse files Browse the repository at this point in the history
竟然一直没人发现吗
  • Loading branch information
sumneko committed Jan 20, 2025
1 parent 8716dfe commit e39e90d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/tools/y3json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import * as jsonc from 'jsonc-parser';

function formatNumber(value: number): string {
// 将数字转换为字符串
let valueStr = value.toString();
// 检查是否包含小数点
if (valueStr.includes('.')) {
return valueStr;
} else {
return value.toFixed(1);
}
}

/**
* 编辑器使用的 JSON 格式,读写时会遵循编辑器的格式规范
*/
Expand Down Expand Up @@ -106,12 +117,12 @@ export class Y3Json {
};
case 'number': {
if (fixed) {
return value.toFixed(1);
return formatNumber(value);
} else {
if (typeof currentData2 === 'bigint') {
return value.toString();
if (typeof currentData2 === 'number') {
return formatNumber(value);
} else {
return value.toFixed(1);
return value.toString();
}
}
};
Expand Down

0 comments on commit e39e90d

Please sign in to comment.