z0mgItsJohn Posted September 5, 2008 Share Posted September 5, 2008 (edited) 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 September 5, 2008 by John2006 Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
DW1 Posted September 5, 2008 Share Posted September 5, 2008 Easy enough: $dec = 0.661 MsgBox(0, "Test", "Dec = " & $dec & @CRLF & "Percent = %" & DecToPercent($dec)) Func DecToPercent( $DecVal ) Return $DecVal * 100 EndFunc AutoIt3 Online Help Link to comment Share on other sites More sharing options...
baghenamoth Posted September 6, 2008 Share Posted September 6, 2008 (edited) 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 September 6, 2008 by baghenamoth Link to comment Share on other sites More sharing options...
DW1 Posted September 6, 2008 Share Posted September 6, 2008 @baghenamoth, indeed, good call on the formating AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Malkey Posted September 6, 2008 Share Posted September 6, 2008 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) EndFuncInteresting 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. Link to comment Share on other sites More sharing options...
z0mgItsJohn Posted September 6, 2008 Author Share Posted September 6, 2008 thanks... :3 - John Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
baghenamoth Posted September 6, 2008 Share Posted September 6, 2008 (edited) 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 September 6, 2008 by baghenamoth Link to comment Share on other sites More sharing options...
monoceres Posted September 6, 2008 Share Posted September 6, 2008 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now