Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round to ANY value equation,, ie..25-50-100-13 anything 2

Status
Not open for further replies.

Box

Mechanical
Mar 11, 2002
6
This may help someone. I recently developed a spreadsheet that calculated some pressure settings for a machine I was in charge of. The pressure gage read in 50 psi incriments, but my spreadsheet output was rounded to the nearest 1 psi. Excel will round to decimal places, not numbers, ie..1-10-100-etc..., or 0.1-0.01-0.001 etc. So I developed an equation that will round to the nearest set value, being any number, interger or otherwise. You could round to the nearest Pi if you wanted to. So here it is:

# = the number you want to round
RN = the number to round to
IP = take the interger part

Rounded Number = IP[(#/RN)+.5] * RN

Basically, take your number #, and divide it by what you want to round to, RN. Add .5 to it, and take the integer part. Then multiply by the RN number again.

Good luck to all, hope this helps someone.

Gary
 
MROUND(number,multiple)

Number is the value to round.

Multiple is the multiple to which you want to round number.

Remarks
Box,
doesn't Excel "MROUND()" function do the same?
Here is how Excel Help explains it:
___________________________________
MROUND rounds up, away from zero, if the remainder of dividing number by multiple is greater than or equal to half the value of multiple.

Examples

MROUND(10, 3) equals 9

MROUND(-10, -3) equals -9

MROUND(1.3, 0.2) equals 1.4

MROUND(5, -2) equals #NUM!
____________________________________________
Or I did not catch something?
gearguru
 
That is a great function. I never knew it existed. I've been using Excel for about 6 years, and never had any training. So when I couldn't find a function to do what I wanted, I had to make up my own.

Thanks for pointing this out. But.... My equation could be used anywhere. Fortran doesn't have a rounding function, or it didn't when I used to use it. And I'm sure several of the newer languages can't do that. So maybe someone can use it that way.

But thanks for the update on Excel. Just shows my own ignorance.

Gary
 
Gary,

An application like Excel has so much functionality it's almost impossible to know everything about it. That's what is great about these forums (try this experiment: ask your question here and also ask the 'Office Assistant' then compare results [wink]).

Btw, I recall using a variation on your function in a GW-BASIC program years ago!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor