Jump to content

Random() (comma seperator)


ptrex
 Share

Recommended Posts

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 ?

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

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())
Link to comment
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.

Link to comment
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

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...