Sign in to follow this  
Followers 0
AvgGamerGuy

Need some help with StringFormat and an integer

3 posts in this topic

#1 ·  Posted (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 by AvgGamerGuy

Share this post


Link to post
Share on other sites



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!

Share this post


Link to post
Share on other sites

He said he answered his own question.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0