View unanswered posts | View active topics It is currently Fri Apr 20, 2018 5:05 am

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Why 59/2=29.0 in %f
Author Message
Rookie

Joined: Sat Jul 13, 2013 3:19 am
Posts: 1
Why 59/2=29.0 in %f
 Code:task main(){   while(1)   {      nxtDisplayTextLine(3,"%f",59/2);      wait1Msec(100);   }}

How can make it correct?
Thank.

Sat Jul 13, 2013 3:30 am
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Re: Why 59/2=29.0 in %f
In integer math, 59/2 = 29. You aren't saving the result in a float, or type casting the result as a float. "%f" tells the function to format the value as a float, but the parameter you are passing is integer (i.e. 59/2).

_________________
Matt

Sat Jul 13, 2013 11:05 am
Professor

Joined: Sat May 18, 2013 1:24 pm
Posts: 271
Location: Olympia, WA
Re: Why 59/2=29.0 in %f
A quick way to fix this would be to use:
 Code:nxtDisplayTextLine(3,"%f",(float)59/2);

Of course, if these things bother you, you're welcome to convert ("cast") both numbers to a float.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

Sat Jul 13, 2013 7:05 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 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