题解 | #取近似值#
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let num = null;
const getApproximateValue = (value: number) => {
const decimal = value % 1;
return decimal >= 0.5 ? Math.ceil(value) : Math.floor(value);
}
rl.on('line', function (line) {
num = Number(line);
});
rl.on('close', () => {
console.log(getApproximateValue(num));
})
查看15道真题和解析