I need to round in ice to display an approximation of some points. But this is not implemented. Is there any way to?
You could take say 123456789 and if you want to round it to the nearest 100th you could divide by 100, (so you'd have 1234567 ) then multiply by 100 to get back up to 123456700. Be warned ICE just chops off the decimals so don't expect great rounding from this.

Maybe PT_ has a better way than this. You can try digging around the docs more. Smile
EDIT: Nope, Womp had the better way, also jcgter had a good idea too Razz
What TLM suggested above is known as truncating, which is not the same as rounding. Since ICE does have the remainder() command, you can round to the nearest nth like this:

Code:
if remainder(X,n)≥(n/2)
X+n→X
End
X-remainder(X,n)→X

(Where X is the number you want to round) is just a standard manual rounding.
I don't think ICE supports treating booleans as integers, but in pure basic, you could do something like this:

Code:
X+n(remainder(X,n)≥n/2)-remainder(X,n→X

Which of course wouldn't be needed because you have the round() command but I'm just saying.. Razz
You can do what TheLastMillennial said for any number and any value. If you want to round to the nearest 10th, divide by ten and re-multiply, et cetera. This will work until the next version of ICE is released, since then floats will be added.

A slow way is to keep subtracting 1 until it's divisible by your rounding number, but I don't actually know if you can check for remainders in ICE. If you want to, you can also subtract 1 until the last numbers are the last numbers of what you want. 12345 - 1(45) = 12300, and you can check the last two digits by some extra tedious code.

The best thing to do is to post in the ICE compiler thread for a feature request: ADD ROUNDING.
mr womp womp wrote:
What TLM suggested above is known as truncating, which is not the same as rounding. Since ICE does have the remainder() command, you can round to the nearest nth like this:

Code:
if remainder(X,n)≥n
Then
X-remainder(X,n)+n→X
Else
X-remainder(X,n)→X
End

(Where X is the number you want to round) is just a standard manual rounding.


for n would you'd type in the number you want it rounded to?
Jcsq6 wrote:
mr womp womp wrote:
What TLM suggested above is known as truncating, which is not the same as rounding. Since ICE does have the remainder() command, you can round to the nearest nth like this:

Code:
if remainder(X,n)≥n
Then
X-remainder(X,n)+n→X
Else
X-remainder(X,n)→X
End

(Where X is the number you want to round) is just a standard manual rounding.


for n would you'd type in the number you want it rounded to?

yes, like if you want it to the nearest 8th, you would put 8
jcgter777 wrote:
The best thing to do is to post in the ICE compiler thread for a feature request: ADD ROUNDING.

I completely agree, although the round() command is usually used with decimal numbers, so PT_ might actually include it in an upcoming update along with dceimal numbers
jcgter777 wrote:
The best thing to do is to post in the ICE compiler thread for a feature request: ADD ROUNDING.

This is already a feature that PT_ is planning to add, as seen here.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement