题解 | #取近似值#
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here while(line = await readline()){ // line输入是string类型,需要转成float类型 const floatNum = parseFloat(line); // 强制类型转换,取出整数部分 const intNum = parseInt(floatNum); // 两数作差和0.5作比较,小于取整数,大于向上取整 if((floatNum - intNum) < 0.5) { console.log(intNum); } else { console.log(intNum + 1); } } }()