Jump to content
UBot Underground

[library] Missing Functions - Round(Input,Digits) # New Ver.1.1 / 10/14/2012


Recommended Posts

 

 

Although I believe these should actually be implemented as core functions in UBot, there are some math functions that I missed when coding, such as INT (Integer), Round, etc...

 

I decided to write one for my own use and to share with you guys here (please test it and see if I missed something?)

 

So I started with a Round function, with two input parameters:

  1. first the number to be rounded
     
  2. second, the number of digits allowed as decimals in the result

The code would have been simpler in most cases, but to cover some extremes and some particular instances and combos, it kinda... grew... lol

 

It accepts Inputs with or without decimals and it will round up to 10 from 5 included, or down to 0 till 5 excluded.

 

Examples:

  • 1.5 -> 1.5 with 1 digit,

OR
  • 1.5 -> 2 with 0 digits

OR
  • 1.5 -> 1.50000 with 5 digits

-----

  • 0.99 -> 1.0 with 1 digit,

OR
  • 0.99 -> 1 with 0 digits

OR
  • 0.99 -> 1.00000 with 5 digits

-----

  • 1.456 -> 1.46 with 2 digits,

OR
  • 1.456 -> 1.5 with 1 digit,

OR
  • 1.456 -> 2 with 0 digits,

and so forth...

 

The package contains actually 2 functions, where the Round Func calls the Round10 function repeatedly, so you need to copy both functions into your bots in order to work properly

 

Here it is, feel free to use it in all your bots, even commercial, without any attribution, etc...

It's just my way to thank this great community.

(A LIKE might be nice though... :P ha, ha, ha...)

Round-Function-V1.1.ubot

  • Like 3
Link to post
Share on other sites

I have noticed 3 types of various errors, 2 of them minor (happening in very rare situations) and one of them major (results were wrong when the first decimal(s) were zeros.

 

I have corrected all 3 errors and tested more extensively.

 

So far it looks like it finally works as expected, so I changed the library above to reflect the edits.

 

-----

 

New Example:

  • 1.0456 -> 1.05 with 2 digits,

OR
  • 1.0456 -> 1.0 with 1 digit,

OR
  • 1.0456 -> 1 with 0 digits,

OR
  • 1.0456 -> 1.046 with 3 digits,

and so forth...

 

-----

 

If you downloaded it before, please replace the old code with this new one.

(re-attached to first post)

 

Enjoy!

Link to post
Share on other sites
  • 11 months later...

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...