Jump to content
43oh

casting or converting numeric types to string in Energia


Recommended Posts

I'm new to energia development, and I would like an example of how to convert a numeric value to a string for output.  Often, the launchpad LCD modules will support output for strings, but I have not found a good way to convert a number into a string for output.

 

I am getting a reading into variable t I want to display on the 2.2 Touch LCD module.  My available output command is .text(x,y,string); So I write;

 

float t = dht.readTemperature();  

myScreen.Text(10,10,"Temp");

 

Next I want to output the value to t to the screen.  How would you go about doing this?

 

Thanks so much!

 

Ronnie

 

Link to post
Share on other sites
Serial.println(1.23456, 0) gives "1"
Serial.println(1.23456, 2) gives "1.23"
Serial.println(1.23456, 4) gives "1.2346"
See the Serial print class description here: http://arduino.cc/en/Serial/Print
 
The MSP430 does not have a floating point unit and using floating points will add about 4k of floating point emulation code to your sketch plus it will make things unnecessarily slow. 

See Rei Vilo's example in the DHT library posted here for how to avoid using floats in your code http://forum.43oh.com/topic/2239-solved-dht22-temp-rh-one-wire-sensor-on-energia/#entry19474

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...