AutoHotkey Community

It is currently May 27th, 2012, 12:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Round() not working?
PostPosted: April 14th, 2010, 7:30 pm 
Offline

Joined: October 21st, 2009, 6:55 pm
Posts: 48
For some reason I cannot get Round() to work at all. The documentation seems pretty straight forward so I am not sure what I am messing up here.

Even the simplest of examples aren't working:

Code:

StartPress = 1650
Sum1 = 28

Div1 := StartPress/Sum1
MsgBox, %Div1% ;Returns 58.928571
Round(Div1, -1)
MsgBox, %Div1% ;Returns the same value 58.928571, should be 60



I am trying to achieve something a little more complex. I want to round all the numbers in an array to the nearest 50 (e.g. 50, 150, 200...) by running a loop but even the example above will not work.

Any help would be greatly appreciated :D . Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 7:49 pm 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
Code:
StartPress = 1650
Sum1 = 28

Div1 := StartPress/Sum1
MsgBox, %Div1% ;Returns 58.928571
Div1 := Round(Div1, -1)
MsgBox, %Div1%

Give that a go


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 7:54 pm 
Offline

Joined: October 21st, 2009, 6:55 pm
Posts: 48
Nice it seems to work. Thank you. :D

Just so I understand for the future... these functions only operate within another expression? Sorry for the newb questions. :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 9:19 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6074
Location: San Diego, California
You treated the function Round() as though it were a command.

A function is a portion of code that may accept parameters and may provide a result
which may be assigned to a variablem such as :arrow: z = function(x, y)

A command is a portion of code that may accept parameters and may provide a result.
The result is provided by modifying one or more of the parameters.
MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl

http://www.autohotkey.com/docs/Functions.htm#intro

http://www.autohotkey.com/docs/Variables.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 10:12 pm 
Offline

Joined: October 21st, 2009, 6:55 pm
Posts: 48
Thanks for clearing that up. I got a lot to learn still.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2010, 11:48 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
I added a function to mimic a command... :)
Code:
StartPress = 1650
Sum1 = 28

Div1 := StartPress/Sum1
MsgBox, %Div1% ;Returns 58.928571
RoundIt(Div1, -1)
MsgBox, %Div1%

RoundIt(ByRef Div1, N)
  Div1 := Round(Div1, N)
Return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, jrav, MSN [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group