- double类型转换到char*
1 char buffer[128]; 2 double value = 12.2345678; 3 _gcvt(value, 5, buffer);//5有效数字 4 printf("%s", buffer);
- unsigned int类型转换到char*
1 unsigned int num = 32; 2 char str[32] = { 0 }; 3 //以2进制方式转换 4 _ultoa(num, str, 2); 5 printf("%s ", str); 6 7 //以8进制方式转换 8 _ultoa(num, str, 8); 9 printf("%s ", str); 10 11 //以10进制方式转换 12 _ultoa(num, str, 10); 13 printf("%s ", str); 14 //以16进制方式转换 15 _ultoa(num, str, 16); 16 printf("%s ", str);
- int类型转换到char*
1 int num = -32; 2 char str[32] = { 0 }; 3 _ltoa(num, str, 2); 4 printf("%s ", str); 5 6 _ltoa(num, str, 8); 7 printf("%s ", str); 8 _ltoa(num, str, 10); 9 printf("%s ", str); 10 _ltoa(num, str, 16); 11 printf("%s ", str);
- 获取double类型的数据信息(1)
1 double data = 12345.4567; 2 3 int decimal;//整数的位数 4 int sign;//1代表负,0代表证 5 int precision = 9;//数字的宽度,强行指定 6 char *buffer;//指针 7 8 //把double类型转化为char* 9 buffer = _ecvt(data, precision, &decimal, &sign);//自动分配内存 10 printf("buffer=%s ", buffer); 11 printf("sign=%d ", sign); 12 printf("decimal=%d ", decimal); 13 printf("precision =%d ", precision);
- 获取double类型的数据信息(2)
1 double data = 12345.4567; 2 3 int decimal;//整数的位数 4 int sign;//1代表负,0代表证 5 int precision = 4;//小数点后的精度 6 char *buffer;//指针 7 8 buffer=_fcvt(data, precision, &decimal, &sign); 9 printf("buffer=%s ", buffer); 10 printf("sign=%d ", sign); 11 printf("decimal=%d ", decimal); 12 printf("precision =%d ", precision); 13