Advertisement

Convert float to string

Started by May 08, 2002 10:42 AM
0 comments, last by Xces 22 years, 9 months ago
How do i convert a float to a string (with 10 decimals or so) so i can display it in a messagebox?
Allready found it;

--------
Example
--------

    // SPRINTF.C: This program uses sprintf to format various// data and place them in the string named buffer.#include <stdio.h>void main( void ){   char  buffer[200], s[] = "computer", c = 'l';   int   i = 35, j;   float fp = 1.7320534f;   // Format and print various data:   j  = sprintf( buffer,     "\tString:    %s\n", s );   j += sprintf( buffer + j, "\tCharacter: %c\n", c );   j += sprintf( buffer + j, "\tInteger:   %d\n", i );   j += sprintf( buffer + j, "\tReal:      %f\n", fp );   printf( "Output:\n%s\ncharacter count = %d\n", buffer, j );}    


--------
Output
--------
Output:
String: computer
Character: l
Integer: 35
Real: 1.732053

character count = 71

[edited by - Xces on May 8, 2002 11:55:20 AM]

This topic is closed to new replies.

Advertisement