Go Down

Topic: Double to String?? How?? (Read 1 time) previous topic - next topic


Hello I'm new in this and I wanna know how I do to convert a double variable to string??

What I want is this: I got a variable string and I want to add the information that is a double variable

----> something like :  The voltage is = 5.32 V.

My first variable is a string one and is this : frame = "The voltage is = ", and the second one is a double one and is ---> X = analogRead(xpin)

I want to do something like -------------> frame += X

SOMETHING LIKE THAT.......................Somebody can help me?


May 19, 2011, 07:47 am Last Edit: May 19, 2011, 07:50 am by Aeturnalus Reason: 1
Depends on if you're using a cstring (char*) or a String object (string)

The easier way is to use the String object: ([url]http://www.arduino.cc/en/Reference/String[/ur])

Code: [Select]

 String frame = "The voltage is = " + String(analogRead(xpin), DEC) + " V\r\n";

With char*:

Code: [Select]

 char frame[30];
 sprintf(frame, "The voltage is = %.02f V.\r\n", analogRead(xpin));


Uh....  analogRead() returns an unsigned long integer, not a double (double-precision float).
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


I thought the analogRead was an example... or not?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131