Home » excel » c# – MS Excel Currency Rounding Method

c# – MS Excel Currency Rounding Method

Posted by: admin May 14, 2020 Leave a comment

Questions:

Would like to know which rounding method is applied when you use Round() function on Excel?
Also is there a difference when you choose to format a column as currency with two decimal places.
I need to emulate Excel’s results in a C# program I’m writing.

How to&Answers:

Caution: Excel and Excel-VBA use two different algorithms.

In Excel:

=ROUND(0.5,0) returns 1.

=ROUND(1.5,0) returns 2.

In Excel-VBA:

Print Round(0.5,0)
 0 
Print Round(1.5,0)
 2 

VBA uses banker’s rounding: rounds 0.5’s to the nearest even integer. Note that the same logic transfers to lower-order decimal places if you Round to more decimal places. For example, Round(0.05,1) returns zero in Excel-VBA (as opposed to 0.1 in Excel).

This is one of the features of VBA I dislike most. It being inconsistent with Excel makes it even worse.

The number format makes no difference to this issue.