Quote:You might consider posting this to the Programming Examples board and/or submitting it to Inside Sesame as a Tip.
Good idea.
Quote:1. The return type of the Function is declared, so it does not accidentally get forced to an Integer.
Noted and changed.
Quote:2. A separate variable is used to return, rather than taking over an argument. The results of returning a passed in argument can be unpredicatable.
The example on page 70 of the programming guide returns "amount", which is a passed in variable. ???
Erika,
Thanks for your input. Although I didn't notice any anomalies, I have updated the code below to reflect your suggestions.
//########## Begin Custom Rounding Function ##########
Function @cuRnd(Value as double, Places as int) as double
var vNeg as int //Used to handle Negatives properly
var vStr as string
if Value < 0
vNeg = -1
else
vNeg = 1
vStr = @Str(@Abs(Value))
if @Instr(vStr, ".") > 0 //Protects whole numbers when rounding to zero places
{
if @Mid(vStr, @Instr(vStr, ".") + Places + 1, 1) >= 5
vStr = @Str( @TN(vStr) + (1 / @Exp(10, Places)) )
vStr = @Del(vStr, @Instr(vStr, ".") + Places + 1, 10)
}
vStr = @Str(@TN(vStr) * vNeg)
Return @TN(vStr)
End Function
//########## End Custom Rounding Function ##########
BTW, I have a slightly unrelated question. What is the difference between @ToMoney and @ToNumber? They both return a double, and seem to return the same number of digits after the decimal.