char str[20] = ""; float f = 4.5; sprintf(str, "%f", f);
#include <sstream> #include <string> std::ostringstream buffer; float f = 4.5; buffer << f; std::string str = buffer.str();
char* str = new char[30]; float flt = 2.4567F; sprintf(str, "%.4g", flt ); cout<str<<endl;
#include <stdio.h>
#define SIZE 10
int main(void)
{
char buf[SIZE];
int result = 0;
float value = 154.78;
result = snprintf(buf, SIZE, "%f", value);
if (result >= SIZE)
printf("The string has been truncated\n");
printf("The string value of the floating value = %s\n", buf);
return 0;
}
string to float
#include <sstream> string strSalary = "5449.98"; float SalaryInFloat; istringstream mySalaray(strSalary); mySalaray >> SalaryInFloat
'메모 > C/C++' 카테고리의 다른 글
| 유니코드 문자열, 숫자 변환 (0) | 2012.04.17 |
|---|---|
| char* -> WCHAR* (wchar_t*) MultiByteToWideChar 함수 (0) | 2012.04.16 |
| char -> int 변환 (0) | 2012.04.10 |
| Direct2D and Direct3D Interoperability Overview (0) | 2012.04.04 |
| Direct2D dpi, dip (0) | 2012.04.04 |
