Jump to content
Sign in to follow this  
golfinhu

convert values above 1000

Recommended Posts

golfinhu

Good afternoon, someone could help me?

I'm trying to do one function, to eliminate points of values above 1000

eg

U$ 1352,00

to

U$ 1352,00

could someone help me please?

I was thinking of comparing the number of characters, and if larger than 11, use a stringleft and stringright and put them together, but I think there's an easier way to do ... if they can help me, I would greatly appreciate it!

thanks

Share this post


Link to post
Share on other sites
Richard Robertson

Func MakeLessThan1000($money)
    $values = StringRegExp($money, "^U\$ (\d+),(\d\d)$", 1)
    If @error Then Return $money ; doesn't match for some reason...
    $number = $values[0]
    While $number >= 1000
        $number -= 1000
    WEnd
    Return "U$ " & $number & "," & $values[1]
EndFunc

Wrote this up quickly. Haven't tested it. Give it the whole string of "U$ 1352,00" and it will return "U$ 352,00" as long as I did it right.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites
golfinhu

thankyou for your repply, but i'm sorry, wrong in the description

right would be:

example value:

convert this

U$ 1.352,00

to

U$ 1352,00

is basically remove the point, that's

ps: I found the edit button in the post!

Edited by golfinhu

Share this post


Link to post
Share on other sites
Richard Robertson

Oh ok. Yeah I can change the code real quick. Lemme know if this one works.

Func Fix($money)
    $values = StringRegExp($money, "^U\$ (\d*).(\d+),(\d\d)$", 1)
    If @error Then Return $money ; doesn't match for some reason...
    Return "U$ " & $values[0] & $values[1] & "," & $values[2]
EndFunc

Share this post


Link to post
Share on other sites
golfinhu

Oh ok. Yeah I can change the code real quick. Lemme know if this one works.

Func Fix($money)
    $values = StringRegExp($money, "^U\$ (\d*).(\d+),(\d\d)$", 1)
    If @error Then Return $money ; doesn't match for some reason...
    Return "U$ " & $values[0] & $values[1] & "," & $values[2]
EndFunc

it's work, thankyou so much!

Share this post


Link to post
Share on other sites
Richard Robertson

You're welcome. There might be a better way to do it, but if what I did works, then it's fine.

Share this post


Link to post
Share on other sites
darkjohn20

StringReplace the decimal point with ""?

Edited by darkjohn20

Share this post


Link to post
Share on other sites
Richard Robertson

StringReplace the decimal point with ""?

Now see, that's exactly what I'm talking about. Not once did that cross my mind.

Share this post


Link to post
Share on other sites
darkjohn20

StringRegExp is quite slow compared to StringReplace, and is recommended when possible.

Share this post


Link to post
Share on other sites
Richard Robertson

Yeah I know it's slow. I just don't write in AutoIt anymore. I had forgotten the function.

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  

×