Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Round to nearest even number

Status
Not open for further replies.

vinerunner

Aerospace
Joined
Sep 4, 2013
Messages
11
Location
HU
Hi all!

I have the following question:

From an equation I get a number which is not round number but it's between 0-inf.
Let's say 81.321.

I would like to round this number to an even number.

So somehow like this: 81.321 -> 81 -> 82

The point is to get the "nearest" EVEN number.

My idea was that I'll use the floor function to make the rounded number but how can I make a number from that which is even for 100% sure?

Thanks!
 
Roughly, divide by two and do the floor, then multiply by two to get the value you want.
 
Thanks! During the night finally it came to my mind :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top