Solved

JQuery to round up numbers

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

770 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