Sign in to follow this  
Followers 0
ptrex

Random() (comma seperator)

12 posts in this topic

I have noticed that numbers returned from the Random() function, does take in account the International settings of the PC.

like if 7.012654699 is returned, it shows a DOT instead of using a COMMA as a decimal seperator.

In some countries like ours they use a COMMA as decimal seperator and a DOT as thousand seperator.

This might sound trivial but when exporting data Using COM to Excel the figures are not recognized correctly.

I took a look in the helpfile but could not find a function to convert it properly.

Is this correct ?

Share this post


Link to post
Share on other sites



I have noticed that numbers returned from the Random() function, does take in account the International settings of the PC.

like if 7.012654699 is returned, it shows a DOT instead of using a COMMA as a decimal seperator.

In some countries like ours they use a COMMA as decimal seperator and a DOT as thousand seperator.

This might sound trivial but when exporting data Using COM to Excel the figures are not recognized correctly.

I took a look in the helpfile but could not find a function to convert it properly.

Is this correct ?

try this 1:

$a = random (1, 100)
$a = stringreplace ($a, ".", ",")

this should work

Share this post


Link to post
Share on other sites

I have noticed that numbers returned from the Random() function, does take in account the International settings of the PC.

like if 7.012654699 is returned, it shows a DOT instead of using a COMMA as a decimal seperator.

In some countries like ours they use a COMMA as decimal seperator and a DOT as thousand seperator.

This might sound trivial but when exporting data Using COM to Excel the figures are not recognized correctly.

I took a look in the helpfile but could not find a function to convert it properly.

Is this correct ?

Random return what is usable by autoit.

It is true that Autoit works only with English/American number. So it is not a bug but the decimal point/coma has to be handle by the scripter.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

try this 1:

$a = random (1, 100)
$a = stringreplace ($a, ".", ",")

this should work

What happens when you have

$a = random(1000, 10000)

$a could equal 8,473.3844. How do you propose a string replace? I would instead do something like

$a = random(1000, 10000)
 $a = StringReplace($a, ',', '\')
 $a = StringReplace($a, '.', ',')
 $a = StringReplace($a, '\', '.')
 MsgBox(0, '', $a)
Edited by MSLx Fanboy

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

What happens when you have

$a = random(1000, 10000)

$a could equal 8,473.3844.

No it can't. It might equal 8473.3844 but there will not be a comma in there.

Share this post


Link to post
Share on other sites

hehe, nevermind then B)


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

as it is not a bug I move it to Support forum so you can continue the discussion if you need B)

Share this post


Link to post
Share on other sites

@Nuffilein805

Your solution solved the problem. Thanks

Anyhow shouldn't there be any standard functions in AutoIT, to support these kind of conversions.

Isn' t is a good idea to have some kind of International support available, since AutoIt is used internationally.

Share this post


Link to post
Share on other sites

ok i just made a udf for that

here it is:

$a = random (1, 100)
$b = DOT2COMMA($a)
msgbox (0, $a, $b)

Func DOT2COMMA($number)
    Select
    Case StringInStr ($number, ".")
        $number = StringReplace ($number, ".", ",")
        Return $number
    Case StringInStr ($number, ",")
        $number = StringReplace ($number, ",", ".")
        Return $number
    EndSelect
EndFunc

+ a little demo

works fine here

dot2comma.au3

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