JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,687
- Office Version
- 365
- Platform
- Windows
I ran into a little oddity that turned out to be a disagreement between the Round and FormatNumber functions
These results are from the Immediate window in a UDF that is interrupted at a breakpoint. The variable Value is defined as double. Its current value is the result of 5-6 calculations.
The value of Value in the Watch window is also "30.437499995".
What's going on here?
These results are from the Immediate window in a UDF that is interrupted at a breakpoint. The variable Value is defined as double. Its current value is the result of 5-6 calculations.
Code:
?value
30.437499995
'If I round it to 8 decimal places, I don't get 30.4375 as expected
?round(value,8)
30.43749999
'But if I round it to 7, I do
?round(value,7)
30.4375
'But if I round the same value as a literal, I get the expected result
?round(30.437499995,8)
30.4375
'The FormatNumber function gets it right at 8 decimal places
?formatnumber(value,8)
30.43750000
'It turns out value is actually slightly larger than 30.43749999
?value = 30.4375
False
?value - 30.4375
-5.00000396641553E-09
The value of Value in the Watch window is also "30.437499995".
What's going on here?
Last edited: