JavaScript: Round Number - round() not working
Question by Guest | 2015-05-05 at 18:24
Is there any simple possibility to round numbers in JavaScript? For example, a function that is able to convert the floating-point number 2.3 to the number 2?
I have already tried to call the function round(), but that is not working for me. On the Internet, I have found some confusing instructions not helping me at all. Isn't there any easy solution?
Related Topics
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
PHP: Rounding Numbers
Tutorial | 0 Comments
Delphi/Lazarus: Function to Round Number to any Position after or before Decimal Point
Tutorial | 0 Comments
jQuery: Scroll up and down with and without JavaScript
Tip | 0 Comments
JavaScript: Show and hide HTML area by clicking a link
Tutorial | 0 Comments
jQuery: Disable Submit Button if no Checkbox is selected
Tutorial | 7 Comments
JavaScript: Create and Use Arrays
Info | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
With just calling round(), it is not working. Instead, you have to take Math.round().
Here is a small example:
The result of 10 / 4 is 2.5. We are rounding this result and we are getting 3.
Note: A value of 2.49 will be rounded down, a value of 2.5 will be rounded up.
2015-05-06 at 14:34