Double to string
-
I know this sounds like a stupid question... I need to convert a double to a string to output it with SetWindowText(). I know how to get the string into the double (using atof() ), is there a better way to do it though? Thanks... i'm just getting into C++ and windows programing from Perl and PHP and would appriciate any help. :)
-
I know this sounds like a stupid question... I need to convert a double to a string to output it with SetWindowText(). I know how to get the string into the double (using atof() ), is there a better way to do it though? Thanks... i'm just getting into C++ and windows programing from Perl and PHP and would appriciate any help. :)
strDouble.Format(_T("%2f"), dDouble); This will work just fine, it will give you a precision of 2. Replace the 2 with however many numbers after the decimal you want it to be precise to. Bret Faller Odyssey Computing, Inc.
-
I know this sounds like a stupid question... I need to convert a double to a string to output it with SetWindowText(). I know how to get the string into the double (using atof() ), is there a better way to do it though? Thanks... i'm just getting into C++ and windows programing from Perl and PHP and would appriciate any help. :)
To get a double into a string: double num = 10.0; CString str; str.Format("%d", num); something.SetWindowText(str); The syntax for Format probably looks really ugly if you've never programmed in C, but that %d grabs a double from after the comma and sticks it in there as a string. enjoy :-D Jake
-
I know this sounds like a stupid question... I need to convert a double to a string to output it with SetWindowText(). I know how to get the string into the double (using atof() ), is there a better way to do it though? Thanks... i'm just getting into C++ and windows programing from Perl and PHP and would appriciate any help. :)
-
To get a double into a string: double num = 10.0; CString str; str.Format("%d", num); something.SetWindowText(str); The syntax for Format probably looks really ugly if you've never programmed in C, but that %d grabs a double from after the comma and sticks it in there as a string. enjoy :-D Jake
-
To get a double into a string: double num = 10.0; CString str; str.Format("%d", num); something.SetWindowText(str); The syntax for Format probably looks really ugly if you've never programmed in C, but that %d grabs a double from after the comma and sticks it in there as a string. enjoy :-D Jake
-
I know this sounds like a stupid question... I need to convert a double to a string to output it with SetWindowText(). I know how to get the string into the double (using atof() ), is there a better way to do it though? Thanks... i'm just getting into C++ and windows programing from Perl and PHP and would appriciate any help. :)
The examples so far have been wrong, %d is the format string for ints. Use %lf ("long float") for doubles. --Mike-- http://home.inreach.com/mdunn/ A recent survey reports that 1/4 of all internet users in England surf for porn. The other 3/4 just didn't want to admit it.
-
strDouble.Format(_T("%2f"), dDouble); This will work just fine, it will give you a precision of 2. Replace the 2 with however many numbers after the decimal you want it to be precise to. Bret Faller Odyssey Computing, Inc.
Actually I believe you need to use %.2f to get a precision of 2...what you have will produce a string that containts a number with 2 overall digits. -Jesse
-
strDouble.Format(_T("%2f"), dDouble); This will work just fine, it will give you a precision of 2. Replace the 2 with however many numbers after the decimal you want it to be precise to. Bret Faller Odyssey Computing, Inc.
Actually I believe you need to use %.2f to get a precision of 2...what you have will produce a string that containts a number with 2 overall digits -Jesse