tooltrainer 12 Posted November 10, 2012 Report Share Posted November 10, 2012 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! Quote Link to post Share on other sites
Legend 181 Posted November 10, 2012 Report Share Posted November 10, 2012 This what you're looking for? http://www.ubotstudi...ver11-10142012/ or http://www.ubotstudio.com/forum/index.php?/topic/8340-round/ Quote Link to post Share on other sites
k1lv9h 76 Posted November 10, 2012 Report Share Posted November 10, 2012 Hi, Sample using javascript Math.ceilCodeset(#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 Quote Link to post Share on other sites
tooltrainer 12 Posted November 10, 2012 Author Report Share Posted November 10, 2012 Thanks guys! Only thing is, I'm not looking for a true "round", but for a "round down". For instance I'd want to round 2.8 down to 2. Any pointers? Quote Link to post Share on other sites
k1lv9h 76 Posted November 10, 2012 Report Share Posted November 10, 2012 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 Quote Link to post Share on other sites
tooltrainer 12 Posted November 10, 2012 Author Report Share Posted November 10, 2012 Very nice Kevin, thanks for pointing that out! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.