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 / 2538
2537  |  2539
Subject: 
Re: Converting a float to an integer
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Wed, 8 May 2002 16:11:20 GMT
Viewed: 
2352 times
  
In lugnet.robotics.rcx.legos, Michael Marklew writes:
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.

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 need to
convert to int's?  Does legOS support standard I/O?  If so, what is stdin
and stdout?  Are files supported, and if so were do the files reside?

Good Luck,

Dean Hystad



Message has 1 Reply:
  RE: Converting a float to an integer
 
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)

Message is in Reply To:
  Converting a float to an integer
 
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)

4 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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