Rex Posted November 19, 2018 Share Posted November 19, 2018 (edited) Hi I have this $iFrom = 23000, $iTo = 32000 ; User input, can be anything from 0 to 9999999, but only as INT For $i = $iFrom To $iTo Step 500 $Percent = Int($i / $iTo * 100) GuiCtrlSetData($idLbl_Percent, $Percent) ; Do some thing next But my % calculation is incorrect, I guess it's course of the 'step 500'. But I have no idea on how to do the correct calculation to get my %, either I was sick the day the learned that in school, or I just didn't pay enough attention, to what my teacher thought us So I was hoping that some one at this fine forum, could help me to do the correct calc Cheers /Rex Edited November 19, 2018 by Rex Solved Link to comment Share on other sites More sharing options...
Developers Jos Posted November 19, 2018 Developers Share Posted November 19, 2018 What exactly is wrong and what are you expecting the percentage to be? The script will show the $i value percentage of the $iTo value, which is showing correctly. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Danyfirex Posted November 19, 2018 Share Posted November 19, 2018 Hello. I'm not sure what you're trying to do but this came to my mind. Local $iFrom = 23000, $iTo = 32000 ; User input, can be anything from 0 to 9999999, but only as INT Local $iStep = 500 Local $iTotalSteps = ($iTo - $iFrom) / $iStep Local $iFractionStep = $iTotalSteps / 100 Local $Percent = 0 For $i = $iFrom To $iTo Step $iStep ;~ $Percent = StringFormat("%.2f%",(($i - $iFrom) / $iStep) / $iFractionStep) ;2 decimal point $Percent=Int((($i - $iFrom) / $iStep) / $iFractionStep) ConsoleWrite($Percent & @CRLF) Next Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
mikell Posted November 19, 2018 Share Posted November 19, 2018 ... ? $iFrom = 23000 $iTo = 32000 ; User input, can be anything from 0 to 9999999, but only as INT For $i = $iFrom To $iTo Step 500 $Percent = Int(($i-$iFrom) / ($iTo-$iFrom) * 100) Consolewrite( $Percent & @crlf) ; Do some thing next Danyfirex 1 Link to comment Share on other sites More sharing options...
Rex Posted November 19, 2018 Author Share Posted November 19, 2018 20 minutes ago, Jos said: What exactly is wrong and what are you expecting the percentage to be? The script will show the $i value percentage of the $iTo value, which is showing correctly. Jos Using the example, the % starts at 71, but should start at 0 and go to ~100%. So the math is correct, but don't work as I expected I really need my school money back 27 minutes ago, Danyfirex said: Hello. I'm not sure what you're trying to do but this came to my mind. Local $iFrom = 23000, $iTo = 32000 ; User input, can be anything from 0 to 9999999, but only as INT Local $iStep = 500 Local $iTotalSteps = ($iTo - $iFrom) / $iStep Local $iFractionStep = $iTotalSteps / 100 Local $Percent = 0 For $i = $iFrom To $iTo Step $iStep ;~ $Percent = StringFormat("%.2f%",(($i - $iFrom) / $iStep) / $iFractionStep) ;2 decimal point $Percent=Int((($i - $iFrom) / $iStep) / $iFractionStep) ConsoleWrite($Percent & @CRLF) Next Saludos Some thing like that Yes 24 minutes ago, mikell said: ... ? $iFrom = 23000 $iTo = 32000 ; User input, can be anything from 0 to 9999999, but only as INT For $i = $iFrom To $iTo Step 500 $Percent = Int(($i-$iFrom) / ($iTo-$iFrom) * 100) Consolewrite( $Percent & @crlf) ; Do some thing next thx @mikell that's just what I was looking for. Thx for all the help Cheers /Rex 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