How to round my value 1 #price with Math.ceil()?

Viewed 27

How to round my value 1 #price with Math.ceil()?

<script>

$(function(){
            $('#price, #charge').keyup(function(){
               var value1 = parseFloat($('#price').val()) || 0;
               var value2 = parseFloat($('#charge').val()) || 0;
               $('#sum').val(value1 + value2);
            });
         });
</script>
1 Answers

to round a number using Math.ceil() one should detuct 0.5 from a number then apply that functions.

function round(x) {
  return Math.ceil(x - 0.5)
}

console.log(round(0.2))
console.log(round(0.7))
console.log(round(-0.7))

Related