0

How can i dividing and rounding up in javascript? For example:

var one = 10/4; 

This return 2.5, but i would like receive 3

var two = 120/7;

This return 17.14, but i would like receive 18

etc

How is the best way for this?

wegs
  • 3
  • 1
  • 1
    Ever heard about `Math.ceil()` and `Math.floor()` – Mr. Alien Jun 12 '14 at 17:00
  • possible duplicate of [javascript round always to upper number](http://stackoverflow.com/questions/11194831/javascript-round-always-to-upper-number) – Mr. Alien Jun 12 '14 at 17:05
  • possible duplicate of [How to round up a number in Javascript?](http://stackoverflow.com/questions/5191088/how-to-round-up-a-number-in-javascript) – Liam Aug 07 '15 at 07:30

1 Answers1

5

You can use Math.ceil:

Math.ceil(10/4); //3
dave
  • 62,300
  • 5
  • 72
  • 93