Can AutoIt Turn A Decimal Into A Percent?

Recommended Posts

I Was Wondering Could AutoIt Do This...

Decimal = 0.5, Percent = 50%

Decimal = 0.2, Percent = 20%

Decimal = 0.661, Percent = 66.1%

What I'm Asking Is Could You Write A Function To Go 2 Places To The Right Of The Decimal And Return The Percent..

I Can't Get The Correct Wording.. I Hope Some 1 Can Help Me

- John

Edited by John2006

Latest Projects :- New & Improved TCP Chat

Share on other sites

Easy enough:

```\$dec = 0.661
MsgBox(0, "Test", "Dec = " & \$dec & @CRLF & "Percent = %" & DecToPercent(\$dec))
Func DecToPercent( \$DecVal )
Return \$DecVal * 100
EndFunc```

Share on other sites

or you can try this :

```\$n = 0.661321
MsgBox(0,"Test",DecToPercent(\$n,2))

Func DecToPercent(\$n_DecValue,\$i_OptionalDecimal=2)
Return StringFormat("%." & \$i_OptionalDecimal & "f %%", \$n*100)
EndFunc```
Edited by baghenamoth

Share on other sites

@baghenamoth, indeed, good call on the formating

Share on other sites

or you can try this :

```\$n = 0.661321
MsgBox(0,"Test",DecToPercent(\$n,2))

Func DecToPercent(\$n_DecValue,\$i_OptionalDecimal=2)
Return StringFormat("%." & \$i_OptionalDecimal & "f %%", \$n*100)
EndFunc```
Interesting script.

The variable,\$n, was not declared a Global variable, yet, it is acting like one.

How 'bout that.

Nice optional parameter, I would not have thought of that.

Share on other sites

thanks... :3

- John

Latest Projects :- New & Improved TCP Chat

Share on other sites

Interesting script.

The variable,\$n, was not declared a Global variable, yet, it is acting like one.

How 'bout that.

Nice optional parameter, I would not have thought of that.

oups I should \$n_DecValue instead of \$n in my function....

Func DecToPercent(\$n_DecValue,\$i_OptionalDecimal=2)

Return StringFormat("%." & \$i_OptionalDecimal & "f %%", \$n_DecValue*100)

EndFunc

Edited by baghenamoth

Share on other sites

Interesting script.

The variable,\$n, was not declared a Global variable, yet, it is acting like one.

How 'bout that.

All variables declared outside a function are global

Broken link? PM me and I'll send you the file!

Create an account

Register a new account