JSFiddle - React, Tailwind, and code Playground

JavaScript

function test(val) {
    var x = Math.floor(val);
    return (val - x) > 0.5 ? Math.ceil(val) : (x + 0.5);
}

alert(test(4.53));
alert(test(4.47));