var getDecimal = function(num) { return +(num - Math.floor(num)).toFixed(1); }; var a = prompt(); alert(getDecimal(a));