Solved

JQuery to round up numbers

Posted on 2014-09-15
2
374 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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

734 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