diff --git a/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts b/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts index 17c814f8ef405b8eb5a65543c5ef4228101e82c0..359b025482a1c6bec08b400631a038e9d7a773e0 100644 --- a/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts +++ b/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts @@ -2598,9 +2598,12 @@ export class NumericSemanticCheck implements BaseChecker { logger.error('Failed to getting range info of issue file when generating auto fix info.'); return null; } + + const valueStr = value.getValue(); + const ruleFixText = NumericSemanticCheck.CreateFixTextForIntLiteral(valueStr); const ruleFix = new RuleFix(); ruleFix.range = range; - ruleFix.text = value.getValue() + '.0'; + ruleFix.text = ruleFixText; return ruleFix; } // 非整型字面量 @@ -2610,4 +2613,16 @@ export class NumericSemanticCheck implements BaseChecker { } return this.generateRuleFixForLocalDefine(sourceFile, warnInfo, NumberCategory.number); } + private static CreateFixTextForIntLiteral(valueStr: string): string { + if (!NumericSemanticCheck.IsNotDecimalNumber(valueStr)) { + return valueStr + '.0'; + } + + return valueStr + '.toDouble()'; + } + + private static IsNotDecimalNumber(value: string): boolean { + const loweredValue = value.toLowerCase(); + return loweredValue.startsWith('0b') || loweredValue.startsWith('0x') || loweredValue.startsWith('0o') || loweredValue.includes('e'); + } }