Go Down

Topic: Arduino splits float numbers into two( 12.67 displays 12.00 and 67.00 (Read 369 times) previous topic - next topic

luizm929

What I'm trying to do is just print the entire float number but it keeps spliting. Also any ideas on how to get character by character a float number then concatenate it and display? I 'm still working on this project and so
I may post some more changes later.

Code: [Select]

float incomingByte = 0.00;
void setup()
{
  Serial.begin(9600);//Prepare serial port for use
  Serial.print("Enter floating point between 1000 to -1000:\n");
  //Serial.print(incomingByte);
}
void loop()
{
  if (Serial.available() > 0)
  {
   incomingByte = Serial.parseInt();

   if(incomingByte > 1000 || incomingByte < -1000)
   {
   Serial.print("Sorry this numebre is out of range\n");
   Serial.print("Try again.\n");
   //incomingByte = Serial.parseInt();
   }
   else
   {
   Serial.println(incomingByte); //without this there is no decimal point
   } 
}
  delay(500);//So serial port isn't overwhelmed.
}




spatula

Look at the documentation for Serial.parseInt() : it stops at the first non-digit character. There is also a parseFloat() function that may work for your case.


luizm929

thank you, and yes I looked  and ended up using
Code: [Select]
Serial.parseFloat()

Go Up