Hi,
I have project where i am wanting to read a decimal value through the serial monitor. But all my data truncates to an integer it seems. Below is my code which should do a simple count at 1.1, 2.1, 3.1 etc. but all i get 1 2 3 4 etc.
Thoughts?
float count = 1.1 ;
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop()
{
count = count + 1.0;
Serial.print(count, DEC);
Serial.println();
delay(10); // 1 sec delay to keep things in control
In Arduino libraries up to 0012, there is no built-in way to print a float variable to the serial port. What you're using is casting the value to an integer. There are a number of home-grown functions here to fill that gap. I've heard 0013 will have a float-to-string or float-to-print capability but I don't know the details.
As opposed to printing it in HEX, or as a BYTE value. In computing, the word "decimal" means "in base ten, digits 0 to 9," not particularly "with a decimal point and fractional parts afterward."