DEV Community

yeonseong
yeonseong

Posted on

division operator in javascript

42 / 2 
Enter fullscreen mode Exit fullscreen mode

is 21 of course

42 / 5 
Enter fullscreen mode Exit fullscreen mode

is 8.4, not 8

in javascript / operator no discard the decimal point.

you should use Math.round(), Math.ceil() or Math.floor()

Math.round(42 / 5) // 8
Enter fullscreen mode Exit fullscreen mode

Top comments (0)