ROBOTC.net forumshttp://www.robotc.net/forums/ Question...http://www.robotc.net/forums/viewtopic.php?f=1&t=5686 Page 1 of 1

 Author: sophiesk101 [ Thu Apr 11, 2013 6:18 pm ] Post subject: Question... Is it possible to make the robot round up?? Or does RobotC always round down with a number? Such as 2.777778 comes up as 2.00000.

Author:  Coder A [ Thu Apr 11, 2013 6:43 pm ]
Post subject:  Re: Question...

Of course. You will have to make your own function, though. Here's one:

 Code:int roundup(float numtoround){  if(numtoround==round(numtoround))    numtoround--;  numtoround++;  return numtoround;}

Does that help?

Author:  sophiesk101 [ Thu Apr 11, 2013 6:50 pm ]
Post subject:  Re: Question...

Coder A wrote:
Of course. You will have to make your own function, though. Here's one:

 Code:int roundup(float numtoround){  if(numtoround==round(numtoround))    numtoround--;  numtoround++;}

Does that help?

Yes it does! Thanks! (:

 Author: Coder A [ Thu Apr 11, 2013 8:11 pm ] Post subject: Re: Question... Good! I'm glad I could help.

Author:  RoboDesigners [ Thu Apr 11, 2013 11:30 pm ]
Post subject:  Re: Question...

If you want an approach to round based on typical rules (e.g. 9.6 rounds up, 5.3 rounds down, 5.5 rounds up), you can try:

 Code:int round(float numToRound) {  return (int) (numToRound + 0.5);}

Author:  mightor [ Fri Apr 12, 2013 12:53 am ]
Post subject:  Re: Question...

Or.... you can just use the round() function in ROBOTC
 Attachment: 2013-04-12_06-51-36.png [ 4.56 KiB | Viewed 5198 times ]

 Code:float meh = 2.56;int foo = round(meh);

= Xander

 Author: NeXT-Generation [ Fri Apr 12, 2013 10:34 am ] Post subject: Re: Question... Are we all understanding this question correctly? You want something that will always round up, or round up/down based on whether it's greater or less than x.5? I'm somewhat confused by all the different answers.

 Author: mightor [ Fri Apr 12, 2013 10:44 am ] Post subject: Re: Question... If you want to round up, use ceil(), otherwise use floor(), if you want to round off, like most humans do, use round().= Xander

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/