Pages: [1]   Go Down
Author Topic: Arduino splits float numbers into two( 12.67 displays 12.00 and 67.00  (Read 294 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
}


Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: