Solved

JQuery to round up numbers

Posted on 2014-09-15
2
392 Views
Last Modified: 2014-09-16
How do I round up a number in JQuery?

If I have a var = 1.56 and I want to round that up to 2.
var base = 1.56;

//  I wanted to write back into a form with the input name damage and write its value as 2? 

document.getElementById('damage').value = base;

Open in new window

0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40323860
var base = 1.56;

//  I wanted to write back into a form with the input name damage and write its value as 2?

document.getElementById('damage').value = Math.round(base);
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40324803
Hi ,

Just some addition to the Leakim971's answer.

If you want  to convert decimal value to the nearest integer then use :

document.getElementById('damage').value = Math.round(base);

If you want to convert decimal value always to the upper integer the use:

document.getElementById('damage').value = Math.ceil(base);
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question