Rounding

1. Member
Join Date
Dec 1969
Posts
48

## Rounding

This is driving me crazy, please help.<BR> the following are examples of rounding<BR> pi = 3.14789<BR> now the different rounding functions<BR> round(pi, 2) = 3.15<BR> round(pi, 1) = 3.1<BR> round(pi, 0) = 3<BR> now i have a number taken from the recordcount/2 function<BR> i.e. y = recoundcount/2 (yielding 4.5)<BR> when i round(y, 0) i get a value of 4 returned, this is not correct and i cannot figure out why it will not round properly.<BR><BR>Cint returns values rounded to the nearest even number, same with clng, is there any thing the just rounds to a whole number correctly. i want 4.5 to round to 5, or if the case may be 5.5 to round up to 6<BR><BR><BR>Please help and thanks in advance<BR>

2. Mr Swifty Guest

## RE: Rounding

The function Round obviously rounds down at .5 instead of up.<BR>You could simply add 0.5 to the value before using the function. This should work in every case:<BR><BR>4.4 + 0.5 = 4.9<BR>round(4.9, 0) = 4 , which is correct for 4.4<BR><BR>4.5 + 0.5 = 5<BR>round(5, 0) = 5 , which is what you want<BR><BR>4.6 + 0.5 = 5.1<BR>round(5.1, 0) = 5, so it still gives the right result.<BR><BR>In other words just add this line before round(y, 0):<BR><BR>y = y + 0.5<BR><BR>

3. Mr Swifty Guest

## RE: Rounding - ACTUALLY THAT'S WRONG

Woops, sorry! But I imagine it could be amended somehow.

4. Senior Member
Join Date
Dec 1969
Posts
915

## RE: Rounding

Try using the following...<BR><BR>FormatNumber(pi, x) Where x is the number od digits to round to.<BR><BR>HTH<BR><BR>Jerry

#### Posting Permissions

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