#Convert double to char array/string

20 messages · Page 1 of 1 (latest)

wild dawn
#

First up, i know google exists, but that doesn't give any working results.
I want to convert a double value to a char array.
i tried memcpy: memcpy(sensorText,&sensorValue,sizeof(sensorValue)); but that returns some alien language stuff.
Please help, thanks in advance.

acoustic brambleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

cloud glade
#
union data
{
char tmp[8];
double d_var;
};

int main(){
data obj;
obj.d_var ==1;
for(int x=0; x<8;x++)
printf("%c", obj.tmp[x]);
}
wild dawn
acoustic brambleBOT
#

@wild dawn Has your question been resolved? If so, run !solved :)

cloud glade
wild dawn
#

thank you
i'm trying to understand it: is it one piece of data that is either read as char or as double ? is that correct?

cloud glade
agile flare
wild dawn
#

mmmh
that is the output

vale briar
#

shall we reconstruct the question?

do you really need to convert the double value to char array/char *?
OR
do you just want to print out the number?

#

sprintf()/snprintf() for

do you really need to convert the double value to char array/char *?
printf() for
do you just want to print out the number?

wild dawn
vale briar
#

#embedded-and-electronics

#

and also you're posting in C help channel 😅

wild dawn
#

it is mainly C
and converting a double to an int is not specific to embedded devices. it is C

vale briar
#

not really. it depends on what libraries the embedded compiler have.
It may not have stdio or stdlib since those libraries may be too big for the system.
and I already given the answer (how you do it with std C library)

acoustic brambleBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.