我需要这个 JavaScript 函数只输出整数

I need to have this JavaScript function only output integers

<html>

<script>


function fahrenheitToCelcius(temp) {
    return (parseFloat(temp) - 32) * (5 / 9);
}

function isNumber(value) {
    return typeof (value) != "boolean" && !isNaN(value) && value.length > 0;
}

function minMaxTemp(value, min, max, unit) {
    console.log("function called");
    if (value.length == 0 || value == "-") return value;
    if (!isNumber(value)) return value.substring(0, value.length - 1);

    if (unit == 1) value = fahrenheitToCelcius(value);

    if (parseFloat(value) < min)
        return min;
    else if (parseFloat(value) > max)
        return max;
    else return value;

}
</script>

<table class="center">
    
      <tr>
        <th>Setpoint</th>
        <th><input id="setPoint" type="text" name="setPoint" value="4" onkeyup="this.value = minMaxTemp(this.value, -80, 150, 0)"   /></th>
       
      </tr>
</table>
</html> 

根据你是向下舍入还是向上舍入,你可以使用Math.floor()Math.ceil()

<th><input id="setPoint" type="text" name="setPoint" value="4" onkeyup="this.value = Math.floor(minMaxTemp(this.value, -80, 150, 0))"   /></th>

MDN 文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor

由于从您的预期输出看来您希望小数向下舍入,我建议使用 JavaScript 的 Math.floor 函数将值向下舍入为最接近的整数

Math.floor(3.712)

将return值3