C double转char字符串

找个double转char字符串的代码,国内搜出来的都是些什么狗屎

出去,一搜就有几种不错的方法

方法1:使用sprintf

https://cboard.cprogramming.com/c-programming/38507-double-string-conversion.html 

double d = 123456.1234567899;
char s[50];
 
sprintf(s,"%f", d);
printf("%s\n", s);
 
sprintf(s,"%.10f", d);
printf("%s\n", s);
 
sprintf(s,"%.2f", d);
printf("%s\n", s);

方法2:自己写

https://www.geeksforgeeks.org/convert-floating-point-number-string/

// C program for implementation of ftoa() 
#include 
#include 

// reverses a string 'str' of length 'len' 
void reverse(char *str, int len) 
{ 
	int i=0, j=len-1, temp; 
	while (i

 

你可能感兴趣的:(平平淡淡才是真)