Advertisement

float to string

Started by August 25, 2000 06:49 PM
5 comments, last by miro 24 years, 4 months ago
How do you convert a floating point number to a string in C++? Thanks, miro
Try using this function:

char *_fcvt( double value, int count, int *dec, int *sign );

It's declared in "stdlib.h"

From Online MSVC docs:
Parameters   value     Number to be converted count     Number of digits after decimal point dec     Pointer to store decimal-point position sign     Pointer to store sign indicator   


//Gaijin

Edited by - Gaijin on August 25, 2000 8:04:50 PM
// Gaijin"There is only one way to find out if a man is honest...ask him. If he says yes, you know he is crooked." -- Groucho Marx"Sex isn't the answer. Sex is the question. 'Yes' is the answer" -- Unknown
Advertisement
You can use

char *_gcvt( double value, int digits, char *buffer );

Returns the ptr to buffer

value:Value to be converted
digits:Number of significant digits stored
buffer:Storage location for result

I hope this works for ya
A man on the move, and just sick enough to be totally confident.Damn Right!
Or how about:
    double atof( const char *string );    


baskuenen: That function does exactly the opposite, converts a string to a floating point value (as I''m sure you know )
// Gaijin"There is only one way to find out if a man is honest...ask him. If he says yes, you know he is crooked." -- Groucho Marx"Sex isn't the answer. Sex is the question. 'Yes' is the answer" -- Unknown
Oops, sorry. Posted tooo fast
Thanks for saying so Gaijin - now I know why I look the way I do...stupid

How about sprintf?



Edited by - baskuenen on August 25, 2000 8:55:20 PM
Advertisement
Wow, lots of replies!

Thank you very much.

miro

This topic is closed to new replies.

Advertisement