jdrott1 said:
i'm trying to round my currency string to end in 9. it's for a
pricing application.
this is the function i'm using to get the item in currency:
FormatCurrency(BoxCost, , , , TriState.True)
if an item is 41.87 i want the application to bring it up to 41.89
if an item is 41.84 i want the application to round down to 41.79
does anyone know how i could do this?
Set two decimal places correcting the error in the Int function for proper
mathematical rounding we have a very simple function:
X = Int(10*(X+0.005))/10
Now set one decimal place mathematical and subtract 1c:
X = Int(10 * (X + 0.06)) / 10 - 0.01
Here, 4 rounds up to 9 as per 5 rounding up to 10
& 3 rounds down to 9 as per 4 rounding down to 0
In the correct mathematical method:
IE +1 inside the brackets compensates -1 outside
just as *10 inside the brackets balances /10 outside.
THUS:
Public Function Nanofy(X as Double) as Double
Nanofy = Int(10 * (X + 0.06)) / 10 - 0.01
End Function
Executing:
Dim x=MsgBox("The Value is: $", CStr(Nanofy(CDble(InputBox(_
"Enter a Value","Enter a Value")))),MsgBoxStyle.OkOnly,"The answer is")
Nanofy(41.84) Returns 41.89
Nanofy(41.83) Returns 41.79
To bias rounding upwards,
simply increment the inner bracket sum in isolation.
SO:
Public Function Nanofy(X as Double) as Double
Nanofy = Int(10 * (X + 0.05)) / 10 - 0.01
End Function
Thus executing:
Dim x=MsgBox("The Value is: $", CStr(Nanofy(CDble(InputBox(_
"Enter a Value","Enter a Value")))),MsgBoxStyle.OkOnly,"The answer is")
Nanofy(41.85) Returns 41.89
Nanofy(41.84) Returns 41.79
Good luck...