To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2537
    Converting a float to an integer —Michael Marklew
   Hopefully this isnt a silly question. Does anyone know how to covert a float to an integer? It doesn't appear that the function atoi exists. Michael. (23 years ago, 7-May-02, to lugnet.robotics.rcx.legos)
   
        Re: Converting a float to an integer —Dean Hystad
   (...) float f = 1.4; int i = (int)((i >= 0) ? i + 0.5 : i - 0.5); OR if (f >= 0) i = (int)(i + 0.5); else i = (int)(i - 0.5); This is assuming you want to round to the nearest integer. Just curious, where are you getting the ascii strings that you (...) (23 years ago, 8-May-02, to lugnet.robotics.rcx.legos)
   
        RE: Converting a float to an integer —Michael Marklew
   I have built a plotter and want to draw a diagonal line of varying angles. It requires one motor to run slower then the other at a ratio based on the distance it has to travel compared to the other one. So I do something like this xspeed = (int) (...) (23 years ago, 9-May-02, to lugnet.robotics.rcx.legos)
   
        Re: Converting a float to an integer —Benton Jackson
   It looks like xdist and ydist are integers. You divide an integer by an integer, the answer is an integer. For example, if xdist=5 and ydist=10, you have 5/10, the answer is 0 (with a remainder of 5). So, if you do the multiply first, you will be (...) (23 years ago, 13-May-02, to lugnet.robotics.rcx.legos)
 

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR