Pages: [1]   Go Down
Author Topic: Double to String?? How??  (Read 1164 times)
0 Members and 1 Guest are viewing this topic.
Colombia!!
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
 String frame = "The voltage is = " + String(analogRead(xpin), DEC) + " V\r\n";

With char*:

Code:
 char frame[30];
  sprintf(frame, "The voltage is = %.02f V.\r\n", analogRead(xpin));
« Last Edit: May 19, 2011, 12:50:13 am by Aeturnalus » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8860
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Uh....  analogRead() returns an unsigned long integer, not a double (double-precision float).
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: