Sign in to follow this  
Followers 0
ennio

Problem with Step

6 posts in this topic

Simple code:

$data = "start"
For $j = 0 To 1 Step 0.02
    $data = $data & $j & @CRLF
Next
$docu = FileOpen("testo.txt", 2)
FileWrite($docu, $data)
FileClose($docu)
exit

check the last numbers:

0.88

0.9

0.92

0.940000000000001

0.960000000000001

0.980000000000001

any help is apreciatted

regards,

- ennio

Share this post


Link to post
Share on other sites



try

$data = $data & Round($j,2) & @CRLF

Thank for the reply , but this code should reach to "1"

and for that mistake in the STEP the cycle is not completed

any ideas?

regards..

-ennio

Share this post


Link to post
Share on other sites

yea it is an odd result from the step & you would have to ask the gurus why it does both these things but as another kinda fudge yo could just use For $j = 0 To 1.01 Step 0.02 to get you to 1


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

im not a guru :D but this IS odd.. ive never seen this.... maybe its the decimal put in there? can you use whole numbers instead?

Share this post


Link to post
Share on other sites

Yada yada yada, floating point numbers are imprecise, yada yada yada.

Seriously, I've answered this more times than I care to remember. It is not a bug. It is expected behavior. If you wish to know more I hear there's this thing called the internet that can answer all your "floating point imprecise" questions.

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  
Followers 0