Jump to content

currency format


Recommended Posts

I had looked in forum a simple program Format Number to add coma :

www.autoitscript.com/forum/index.php?showtopic=16376

Global $t, $t1, $final1, $result, $var[2], $final2

    ;$Var = 45678913231
    $var[0] = 123456
    $var[1] = 789012

for $i = 0 to 1
    $result = StringSplit($var[$i], "")

    For $x = $result[0] to 1 Step -1
        $t = $t +1
        MsgBox(0, "", $t)
        If $t = 4 Then
            $final1 = "," & $final1 
            $t = 1
        EndIf
        $final1 =  $result[$x] & $final1
    Next

    MsgBox(0, "Results", $final1)

Next

I using that code to format number more than 1 variable. When read variabel 1 the result is true but the problem is when read next variabel the result is union from current variabel and first variabel.

How to format number each of variabel?

Thank You.

Link to comment
Share on other sites

Is this what you are looking for?

Global $t, $t1, $final1, $result, $var[2], $final2

    ;$Var = 45678913231
    $var[0] = 123456
    $var[1] = 789012

for $i = 0 to 1
    $result = StringSplit($var[$i], "")
    $final1 = ""
    $t = 0
    For $x = $result[0] to 1 Step -1
    $t = $t +1
    MsgBox(0, "", $t)
    If $t = 4 Then
    $final1 = "," & $final1
    EndIf
    $final1 = $result[$x] & $final1
    Next
    MsgBox(0, "Results", $final1)
Next

I wasn't sure if you wanted to add a comma for every 3 numbers, or just for the last 3. This script does the latter.

I've made it reset $final1and $t for each number, which results in what I think you wanted for the examples provided.

I'll have a looksie if I can come up with a simpler solution.

Not exactly a simple solution, but this might be exactly what you want:

http://www.autoitscript.com/forum/index.php?showtopic=11732&view=findpost&p=87193

Edited by Tvern
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...