Jump to content
Sign in to follow this  
z0mgItsJohn

Can AutoIt Turn A Decimal Into A Percent?

Recommended Posts

z0mgItsJohn

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 this post


Link to post
Share on other sites
baghenamoth

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 this post


Link to post
Share on other sites
Malkey

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 this post


Link to post
Share on other sites
baghenamoth

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 this post


Link to post
Share on other sites
monoceres

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!

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  

×