AvgGamerGuy Posted May 11, 2008 Posted May 11, 2008 (edited) I'm having trouble using StringFormat to force the output of the decimal and two zero's behind the decimal of a variable that is an integer. It's not displaying the decimal and the zero's, only the integer. I'm obviously doing something wrong. Can anyone point out my errors? I'm attaching the relevant piece of code Func _GetTotalDue($PaymentNode);--------------------- Local $PaymentArray = _XMLGetValue($PaymentNode) Local $ret_val = 0 Local $FilteredNumber[15] Local $FilteredNumberWithDecimal[15] If IsArray($PaymentArray) Then For $T = 1 to 14 If $T = 1 Then Sleep(10) EndIf $FilteredNumber[$T] = Number(StringReplace($PaymentArray[$T], ",", "")) $FilteredNumberWithDecimal[$T] = StringFormat("%.2f", $FilteredNumber[$T]); here's where i'm having the problem I think <--------------- $ret_val += $FilteredNumberWithDecimal[$T] Send("Payment # " & $T & " is " & $FilteredNumberWithDecimal[$T] & " Running Total is " & $ret_val & @LF); I need to send the text to Word here Sleep(500) Next Send(@lf) Return $ret_val Else Return SetError(1,3,0) EndIf EndFunc; _GetTotalDue----------------------------------- any help would be greatly appreciated! I'm an idiot.....answered my own question....the variable that was not showing the decimal and zeros was not $FilteredNumberWithDecimal[$T] it was $ret_val which I never used StringFormat on! Sorry! Edited May 11, 2008 by AvgGamerGuy
rudi Posted May 12, 2008 Posted May 12, 2008 Hi. As I can't know what the values are you have trouble with use this example to see how it works. Then check with your values. Dim $Values[7] $Values[1]=0 $Values[2]=1000 $Values[3]=33.3 $Values[4]=0.00009 $Values[5]=123.456 $Values[6]=123.444 for $i=1 to 6 $S =StringFormat ("%.2f",$Values[$i]) MsgBox(0, "Result", $S) Next Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now