View unanswered posts | View active topics It is currently Mon Jun 18, 2018 10:55 pm

Reply to topic  [ 3 posts ] 
Why 59/2=29.0 in %f 
Author Message

Joined: Sat Jul 13, 2013 3:19 am
Posts: 1
Post Why 59/2=29.0 in %f
task main()

How can make it correct?

Sat Jul 13, 2013 3:30 am

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post 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).


Sat Jul 13, 2013 11:05 am
Profile WWW
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 271
Location: Olympia, WA
Post Re: Why 59/2=29.0 in %f
A quick way to fix this would be to use:

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).

and also quadrotors. Quadrotors!

Sat Jul 13, 2013 7:05 pm
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.