Jump to content
UBot Underground

How to round a calculation in UBot 4?


Recommended Posts

In searching the forum I only found things that were clearly for much older versions.

 

So in UBot 4, how can we go about rounding a calculation?

 

My application: I'm posting links somewhere and it supports only 20 at a time. But I may have an arbitrary number to post, so I loop through the process of posting 20 links, but I need to know how many times to loop, up front. I can figure this out by taking X number of links, divided by 20. But now say I have 50 links, that's 2.5 times. I'm fine with just truncating down to only 2 times. I don't need to get every last link.

 

How can I round the result down?

 

Thanks all!

Link to post
Share on other sites

Hi,

 

Sample using javascript Math.ceil

Code

set(#num1, 50, "Global")
set(#perpage, 20, "Global")
set(#loopit, $eval("var worknum = {#num1}/{#perpage};
worknumrnd = Math.ceil(worknum);
worknumrnd"), "Global")

 

sample-javascript-math-ceil-001.ubot

 

Kevin

Link to post
Share on other sites

Hi,

 

Sample code using Math.floor:

set(#num1, 50, "Global")
set(#perpage, 20, "Global")
set(#loopit, $eval("var worknum = {#num1}/{#perpage};
worknumrnd = Math.floor(worknum);
worknumrnd"), "Global")

 

sample-javascript-math-floor-001.ubot

 

Kevin

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...