Unwanted negative number on LCD

I have written een sketch that decodes a certain string with data in to some numbers and shows them on a LCD.
But i one circumstance it shows to much data e.g. when the elevation is negative it should display 0.0 .
But if the data in the comammand looks like 1,345.5,-0.0 it shows not 0.0 but at this point it shows -0.0 .
Maybe i missed something in the code but i cant find it.

// Detect a Videre command that looks like 1,aaa.a,eee.e
// if e = negative where waiting for a satilite
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Streaming.h>
#include <Servo.h> 

#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args)  write(args);
#else
#define printByte(args)  print(args,BYTE);
#endif

String readString = "";

float x_axisTemp = 0;
float y_axisTemp = 0;

int videreIndex = 0;              // counter if a Videre command is to be decoded
int decimalPoint = 0;
int dataEastWest = 0;
int teller = 0;

//long _XX = 0L;
//long _YY = 0L;
float _newX_axis = 0L;	// new azimuth for rotor move
float _newY_axis = 0L;	// new azimuth for rotor move

static const double DegreeToRadian = PI/180. ;  // PI/180
static const double RadianToDegree = 1/DegreeToRadian;    // 1 / ( PI / 180 )

boolean videreCommand = false;    // Is set if the first character received is a 0 or 1
boolean videreEastWest = false;   // Set if the pass is on the QTH-West

// Create display instance
//  Arduino analog input 5 - I2C SCL
//  Arduino analog input 4 - I2C SDA
LiquidCrystal_I2C lcdSerial(0x20,20,4);  // set the LCD address to 0x20 for a 20 chars and 4 line display

void setup() {
  Serial.begin(19200);
  lcdSerial.init();                      // initialize the lcd 
  lcdSerial.backlight();
  lcdSerial.print(" Videre Command 1.0"); // so I can keep track of what is loaded

}

void loop() {
  if (Serial.available())  {
    readCommand(Serial.read());
  } 
  else  {
    videreCommand = false;
  }
}

void readCommand(char character)  {
  if (character == ',' || character == '\n' || character == '\r') {
    if (readString.length() >0) {
      switch(videreIndex)  {
      case 0:  
        {
          if(readString == "0" && !videreCommand)   {  // Pass on West so add 180 degrees (flip)
            videreCommand = true;
            videreEastWest = true;
            videreIndex = 1;
          }
          else if(readString == "1" && !videreCommand)   { // Pass on Eat

            videreCommand = true;
            videreEastWest = false;
            videreIndex = 1;
          }
          break;
        }
      case 1:  
        {
          x_axisTemp = convertDegrees(readString);
          if(x_axisTemp > 360)  {
            videreCommand = false;
            videreIndex = 0;
            //            Serial << "Wrong Azimuth, to large (max. 360.0)." << endl; 
          } 
          else  {
            videreIndex = 2;
          }
          break;
        }
      case 2:  
        { 
          y_axisTemp = convertDegrees(readString);
          if(y_axisTemp < 0.0)  { // Waiting for satelite to come in range
            y_axisTemp = 0.0;
            if(videreEastWest)  {
              y_axisTemp = 180.0; 
            } 
            else  { 
              y_axisTemp = 0.0;
            }
          }
          if(y_axisTemp <= 180)  {
            lcdSerial.setCursor(0,1);
            lcdSerial << "AZ/EL " << displayAxis(x_axisTemp);
            lcdSerial.setCursor(13,1);
            lcdSerial << displayAxis(y_axisTemp);
            xyConvert(x_axisTemp, y_axisTemp);
            lcdSerial.setCursor(0,2);
            lcdSerial << " X/Y  " << displayAxis(newXaxis);
            lcdSerial.setCursor(13,2);
            lcdSerial << displayAxis(newYaxis);
            lcdSerial.setCursor(0,3);
          } 
          else { 
            // Wrong elevation, start over again 
          }
          videreIndex = 0;
          videreCommand = false;
          videreEastWest = false;
          break;
        }
      default:  
        {  
          break;
        }
      }
      readString = ""; //clears variable for new input
    }
  }  
  else {     
    readString += character; //makes the string readString
  } 
}

float convertDegrees(String readString)  {
  char carray[readString.length() + 1]; //determine size of the array
  readString.toCharArray(carray, sizeof(carray)); //put readStringinto an array
  float f = atof(carray); //convert the array into a float
}

String displayAxis(double axis)  {
  static char Buffer[7];
  String SString = "";
  if(axis < 10.0)   { 
    SString += " "; 
  }
  if(axis < 100.0)  { 
    SString += " "; 
  }
  dtostrf(axis,4, 2, Buffer);
  return SString += Buffer;
}

void xyConvert(float az, float el)  {

  double azFloat = az * DegreeToRadian;        // One can also use DEG_TO_RAD
  double elFloat = el * DegreeToRadian;
  double _XX = 0L;
  double _YY = 0L;

  _XX = asin(sin(azFloat)*cos(elFloat)) * RadianToDegree;        // One can also use RAD_TO_DEG


  if(el < 0.1) { 
    _YY = 0.1;
  } 
  if(el == 180)  {
    _YY = -90.0;
  }
  else {
    _YY = atan(cos(azFloat)/tan(elFloat)) * RadianToDegree;
  }
  newXaxis = 90 - _XX;
  newYaxis = 90 - _YY;
}

float RadiansToDegrees(float rads)
{
  float RTD = rads * 180/PI;
  return RTD;
}

Maybe i missed something but cant find it

Maybe i missed something but cant find it

One thing you missed telling us was what variable's value is being printed incorrectly.

PaulS:

Maybe i missed something but cant find it

One thing you missed telling us was what variable's value is being printed incorrectly.

          if(y_axisTemp < 0.0)  { // Waiting for satelite to come in range
            y_axisTemp = 0.0;
            if(videreEastWest)  {
              y_axisTemp = 180.0; 
            } 
            else  { 
              y_axisTemp = 0.0;
            }
          }

its y_axisTemp

Would using the abs() function help ?

The problem here is that float values aren't very accurate at times. They're pretty much an approximation of a value.

-0.0 is actually represented as something like -0.0000000000000000000000000001, so what you think of as being equal to 0 is actually not, and when rounded and truncated results in -0.0, not 0.0

You could quite happily put in a "if (whatever < 0) whatever = 0;" to force anything it thinks of as less than 0 to become 0.

It may be a compiler optimisation. There are two types of 0 in floating point, negative and positive. Both can be represented EXACTLY as 0, (not 0.000000000001 or whatever), however both are different as it depends what value is stored in the 'sign' bit. In terms of comparison, (-0.0) == (+0.0) would return true, but in terms of some math functions they differ, for example 1/(+0.0) = +infinity, while 1/(-0.0) = -infinity.
Which zero depends on where it came from, so for example if you round up from a negative number to 0, you get -0, or down from a positive number and you get +0.

In your case it looks like the compiler sees that if the number is <0 (i.e. negative), so it may be choosing a -0.

You could try this:

          if(y_axisTemp <= 0.0)  { // Waiting for satelite to come in range
            y_axisTemp = 180.0;
            if(!videreEastWest)  {
              y_axisTemp = 0.0;
            }
          }

Or, maybe this:

          if(y_axisTemp <= 0.0)  { // Waiting for satelite to come in range
            y_axisTemp = +0.0;
            if(videreEastWest)  {
              y_axisTemp = +180.0; 
            } 
            else  { 
              y_axisTemp = +0.0;
            }
          }

Don't know if it will work or not.

In both, notice the '<=', which means that (-0.0) would be caught and corrected by the if statement, as opposed to <0.0 where a negative 0 would not be corrected.