View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.misc
Ron Rosenfeld[_2_] Ron Rosenfeld[_2_] is offline
external usenet poster
 
Posts: 1,045
Default Formula to identify decimal versus whole numbers

On Wed, 16 Jul 2014 16:51:42 -0700 (PDT), wrote:

I know this is over 5 years old, but I'm in a bit of a bind looking for help. Here is the situation.

I want to express numbers with certain rules at the .5 decimal range. For example, a number like 239.5 would round up to 240 while a number like 238.5 would round down to 238. It would go to the nearest even number based on what the digit previously to it is (even or odd). Otherwise the system would round according to normal rules. I know its a big IF statement but the only part I've been able to code correctly is.

=IF(LOGIC,Roundup(#,0),Rounddown(#,0))

I'm new to coding with excel, so any help would be appriciated.


If you will be dealing only with zero or positive rounding "digits to the right of the decimal", then you can write a simple User Defined Function since the VBA Round Function does what you want.

However, you may also be interested in
http://support.microsoft.com/kb/196652 which discusses implementation of various types of rounding in Excel.

For the Bankers Rounding algorithm:

To enter this User Defined Function (UDF), <alt-F11 opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this User Defined Function (UDF), enter a formula like

=BRound(A1,0)

in some cell.

=====================================
Option Explicit
Function BRound(Num As Double, Optional NumDecPlaces As Long = 0) As Double
BRound = Round(Num, NumDecPlaces)
End Function
=================================