# Math.Round causes results not to match

#### Asdf0qwerty

##### New Member
Hi everyone,

I tried to use the Math.Round function inside my UDF Add-In so that it would return a result rounded of to 2 decimal places.

Also, I have this "test table" wherein I could compare the 1.) Results From Manual (left blue column) from 2.) Results From UDF (right blue column).

I used the IF function to test e.g. =IF(CJ14=CM14,"MATCH", "NO MATCH"). I do not understand why there are "NO MATCH" results even though the columns does match. Why did this happen and what should I do to solve the problem?

1. Here's the image of my worksheet

2. Here's the return statement of my UDF

Code:
``````'This statement returns result into Worksheet Cell
MyCurrencyFunction = Math.Round(CDec(ComputeThis(varX, varY)), 2)``````

I hope anyone can help me out soon. TIA

### Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

#### Richard Schollar

##### MrExcel MVP
How have you generated the values in the first column (ie NOT the UDF column)?

I would have thought a better comparison would be:

=IF(ROUND(CJ14,2)=CM14,"MATCH", "NO MATCH").

#### Asdf0qwerty

##### New Member
@Richard: Thank you for your help Richard. I do apologize for the very late reply. A lot of troubles and deliverables.

Btw, I tried what you told me, and it worked for all records except for 4 records. The results of my UDF were a 1 cent less than the value it is compared to.

Also, I found out that w/o using the Math.Round in my UDF + using your program statement in the cell, worked a 100% correct in all records.

So, is it safe to just return results from my UDF without using Math.Round? Just want to know what you think about this. Cause, well for me since it works then might as well I stick with not using Math.Round.

#### Richard Schollar

##### MrExcel MVP
You probably don't need to do it in the UDF (unless you specifically want values to 2 decimal places) but any time you have floating numbers you may have trouble doing exact comparisons because of the limited precision offered by Excel (and the way computers store floating numbers).

hence, when doing comparisons to other floating numbers you should use a rounding function (on both).

#### Asdf0qwerty

##### New Member
Okay, I'll keep these in mind Richard. Again, thank you for your help and GBY :D.

Replies
6
Views
174
Replies
6
Views
108
Replies
21
Views
482
Replies
4
Views
184
Replies
1
Views
81

1,181,892
Messages
5,932,669
Members
436,850
Latest member
Jasperlee93

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back