Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Rounding numbers

Hi All,

Is there a simple way of doing the following? I am working with percentages by using a basic operator ((number / 365)*100). If the resultant value is below 50% (regardless of how many decimal places there are), the number needs to round down to the nearest whole percent. If the value is above 50%, it should be rounded up to the nearst whole percent.

I have not been able to find a way. Ultimately, I am looking at including this within a function that does the above opertion to convert it to percentage so I can apply other rules to the result, and not having it as a separate function unless there is no other way. I am using IE6.

Any help would be appreciated. I have looked into the round method but couldn't find how to tell it do do what I want.

Cheers,

A

• Try this:-

Code:
```<script type = "text/javascript">
var num = 323;
var a = num/365*100;
if (a < 50) {
var result = parseInt(Math.floor(a));
}
else {
var result = parseInt(Math.ceil(a));
}
</script>```

Instructions on a Swedish chainsaw -- "Do not attempt to stop chain with your hands or genitals."

• ## Users who have thanked Philip M for this post:

longman (06-17-2009)

• Thanks Philip, you're a legend!

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•