How to round a number in JS?

JavaScript: How to round a number in JS?

Use the Math.round(123.45) method to round numbers in Javascript.

If you want to round up or down to that integer, use ceil or floor

For example, Math.ceil(1.01) returns 2. Ceil is short for ceiling.

Math.floor(1.99) returns 1

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to round a number in JS?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the JavaScript language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

How to add comments in PHP

What are some ways you can log debug messages and data in JS?

How to select all rows for a certain month (or day, year or time), using Eloquent

PHP Date commonly used formats

How to set up custom error pages in .htaccess for your Apache server (ErrorDocument)

How to fix the MySQL related "Specified key was too long error" error in Laravel

How can you check if a variable is alphanum (alphanumeric, letters and numbers only) in PHP?

How to block an IP address in .htaccess

How to add a name prefix to all routes in a group?