# Thread: Help with Rounding Up - My first post

#### Hybrid View

1. Registered User
Join Date
May 2013
Posts
3

## Help with Rounding Up - My first post

Hi all – My first post.

I am developing a simple web page form where the visitor can input height and width and the script calculates the area and price.

The script below does this fine.

However, I would like to roundup the answer to the next integer for example if price = 45.678 final output would be 46.

I have tried Math.round(x) but the syntax totally defeats me.

I would be grateful if someone would give me a hand and post the required change to my script below.

Hopefully not a big ask.

Regards

-------------------------

<script type="text/javascript" language="Javascript">

var h1 = 0;
var w2 = 0;
var price = 0;

function calculate () {
// The Calculation: change operator in this equation to change the calculation
price = h1 * w2 * .0005;

var elem;
elem = document.getElementById("h1");
elem.value = h1;
elem = document.getElementById("w2");
elem.value = w2;

elem = document.getElementById("price");
elem.value = price;
}

function setValue(elem) {
var val = 0.0;
if (elem.value != "") {
val = parseFloat(elem.value);
}
else {
val = 0.0;
}
switch (elem.id) {
case "h1": h1 = val; break;
case "w2": w2 = val; break;
}
calculate();
}
</script>

--------------

2. Code:
```elem = document.getElementById("price");
elem.value = Math.round(price);```
Last edited by Padonak; 05-17-2013 at 02:33 PM.

3. Registered User
Join Date
May 2013
Posts
3

Many thanks for such a quick reply.

Where exactly does your addition fit in my script.

Ta

4. there is only one place in your script where you set document.getElementById("price") value, am i wrong?

5. Registered User
Join Date
May 2013
Posts
3
Panonak

Many thanks for your help - All appears to be working as required - and yes there is only one place where "price" is set - Regards

6. good to hear it helped ))