Webolution Designs

May 17 2016

Round and Round

Math…I know…some of you are letting our a collective groan. Let’s face it, not all of us like math, but it is necessary and can be very helpful in developing applications. Fortunately, JavaScript has some built in Math methods to assist us.

  • PI – returns 3.14….
  • round() – round floating point to nearest integer
  • floor() – round floating point down
  • ceil() – round floating point up
  • random() – generate random number between 0 and 1

There is also, min(), max() and abs(), which returns an absolute number.

So if you need to perform any of these mathematical calculations, let the JavaScript engine do it for you.

Note: If you want a random number between numbers other than 0 & 1, you can do that easily enough…

Happy Coding!

Clay Hess

Leave a Reply

Your email address will not be published. Required fields are marked *