April 3, 2012
I found a post on the Arduino forum:
#include<stdlib.h> dtostrf(FLOAT,WIDTH, PRECISION,BUFFER);
(At the bottom of the post, that may help...)
If this works, please let us know and I will add it the Arduino tutorials.
June 16, 2013
Here's how I have done it:
char buffer2; //make buffer large enough for 7 digits
String tempStr = dtostrf(allSensors[i].averageTemp, 7,2,buffer2);
//'7' digits including '-' negative, decimal and white space. '2' decimal places
tempStr.trim(); //trim whitespace, important so ThingSpeak will treat it as a number
The std lib.h is included by default.
January 25, 2014
June 16, 2013
Thanks, gadjet, thats very cool. That led me to read all the String object methods:
October 10, 2015
I used this: -
This takes the float value from my DS18B20 temp sensor.
If anyone is around I used a slightly different take to get decimal values to two decimal places.
I needed 3 values passed to thingspeak. Most of the code below is just debug stuff but I left it in.
The lines that do the work are the FLOAT.
Yes I borrowed the code from another thingspeak member and just tweaked it a little as it seemed slightly more modular and easier to add sensor routines see http://community.thingspeak.com/forum/arduino/ds18b20-temp-sensor/ Raklinks post
float WT = sensors.getTempC(WaterTemp); // was int
float OT = sensors.getTempC(OutsideTemp); // was int
Serial.print("Room Temp is: ");
// read value of 5V solar panel 0 to 500
float LT = (analogRead(A0)); // was int
//String AP = String(analogRead(A0), DEC);
Serial.print(LT/100); // divide by 100 to get voltage produced
// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
updateThingSpeak("field1="+String(WT, DEC) +"&field2="+String(OT, DEC)+"&field3="+String(LT, DEC));
January 10, 2019
Decimals have much higher precision and are usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double/float. Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.
Most Users Ever Online: 166
Currently Browsing this Page:
Guest Posters: 1
Newest Members:Richard, naturepur, Nimper, email@example.com, projectid030, mrlee234
Moderators: cstapels: 460
Administrators: Hans: 405, lee: 457