已知 字符串 a = ‘10.3%’,现需将转换为 字符串’12.3%’
const aNumber = parseFloat('10.3%');
const resultNumber = aNumber + 2;
const resultString = resultNumber.toFixed(1) + '%';
const a = '10.3%';
const target = '12.3%';
// 去掉百分号,将字符串转换为数字
const aNumber = parseFloat(a);
const resultNumber = aNumber + 2;
// 将结果转换为带百分号的字符串
const resultString = resultNumber.toFixed(1) + '%';
console.log(resultString == target);