Jump to content

# Math -> Calculate % in for \$i = xxxx to xxxx Step 500 [SOLVED]

## Recommended Posts

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 by Rex
Solved
##### Share on other sites
• Developers

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

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

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

AutoIt...

##### Share on other sites

... ?

```\$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```

##### Share on other sites
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

## 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
• ### Recently Browsing   0 members

No registered users viewing this page.

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...