View unanswered posts | View active topics It is currently Thu Jul 24, 2014 4:39 pm






Reply to topic  [ 8 posts ] 
Question... 
Author Message
Rookie

Joined: Thu Apr 11, 2013 6:11 pm
Posts: 2
Post 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.


Thu Apr 11, 2013 6:18 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Last edited by Coder A on Thu Apr 11, 2013 8:12 pm, edited 1 time in total.



Thu Apr 11, 2013 6:43 pm
Profile
Rookie

Joined: Thu Apr 11, 2013 6:11 pm
Posts: 2
Post 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! (:


Thu Apr 11, 2013 6:50 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Question...
Good! I'm glad I could help.

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu Apr 11, 2013 8:11 pm
Profile
Novice
User avatar

Joined: Sat Jul 10, 2010 3:06 pm
Posts: 86
Location: Roanoke, VA
Post 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);
}

_________________
Check out my website! www.RoboDesigners.com

VRC Team 2190

Twitter: @RoboDesigners


Thu Apr 11, 2013 11:30 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Question...
Or.... you can just use the round() function in ROBOTC :)
Attachment:
2013-04-12_06-51-36.png
2013-04-12_06-51-36.png [ 4.56 KiB | Viewed 1636 times ]

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

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Apr 12, 2013 12:53 am
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post 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.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Fri Apr 12, 2013 10:34 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Apr 12, 2013 10:44 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.