View unanswered posts | View active topics It is currently Wed May 23, 2018 1:19 am

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Question...
Author Message
Rookie

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

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

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

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

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

Thu Apr 11, 2013 11:30 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Question...
Or.... you can just use the round() function in ROBOTC
 Attachment: 2013-04-12_06-51-36.png [ 4.56 KiB | Viewed 4820 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
Senior Roboticist

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

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 8 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning