Is there a: convert float to integer function??

This is a discussion on Is there a: convert float to integer function?? within the C Programming forums, part of the General Programming Boards category; There are standard functions like atof(), itoa()...... my question is: Is there a function to convert float to string...?? I ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    32

    Is there a: convert float to integer function??

    There are standard functions like atof(), itoa()......

    my question is: Is there a function to convert float to string...??

    I searched the MSDN library, but cannot find "ftoa()"....does it have other names..??

    _____

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    sprintf(string, "%f", floatnum);
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Quote Originally Posted by AssistMe
    Is there a: convert float to integer function??

    ...

    my question is: Is there a function to convert float to string...??
    Which is it? float to int or float to string? First one, second one... both?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char buf[ BUFSIZ ] = {0};
    int x = 0;
    float f = 0.0;
    
    f = 123.45;
    x = f; /* float to int */
    
    sprintf( buf, "%f", f ); /* float to string */
    The answer to your questions is no and yes respectively. There isn't a function to convert a float to int, but you don't need one.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    32
    Opppss.......my mistake...

    I mean float to string

    _____

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21