I remember working with Round function. There was a scenario where it was returning wrong value.
'Let us see the example
Now when i call this function i get the expected value. 30.745 is returned as 30.75.
Hope this helps my reader.
'Let us see the example
dblValue=30.745Reason behind this is
dblRoundedValue=Round (dblValue,2) 'Round for two digits after decimal
***************
Output was 30.74 instead of 30.75.
***************
The Round function performs round to even, which is different from round to larger. ... If expression is exactly halfway between two possible rounded values, the function returns the possible rounded value whose rightmost digit is an even number.This is not what i was looking for. For me the values has to be 30.75. I developed a small piece of code which works absolutely fine for rounding values to larger.
Function Generic_RoundToLarger(dblNumber, intNumDigitsAfterDecimal)
dblRoundedValue= CDbl(FormatNumber(dblNumber, intNumDigitsAfterDecimal))
Generic_RoundToLarger=dblRoundedValue
End Function
Now when i call this function i get the expected value. 30.745 is returned as 30.75.
Hope this helps my reader.
No comments:
Post a Comment