转换双重价值在C字符数组 [英] Convert double value to a char array in C
本文介绍了转换双重价值在C字符数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何转换双重价值在C字符数组?
How do I convert double value to a char array in C?
double a=2.132;
char arr[8];
有没有办法在标准C做到这一点?谁能给任何解决方案?
Is there any way to do this in standard C? Can anyone give any solution?
推荐答案
如果您要存储的双数据,而不是重新读取presentation,则:
If you are about to store the double DATA, not the readable representation, then:
#include <string.h>
double a=2.132;
char arr[sizeof(a)];
memcpy(&arr,&a,sizeof(a));
这篇关于转换双重价值在C字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文