Sending negative float value drom serial.port

Hi, i want to send 4 values from serial port to arduino. and i want to send negative value.
is there away to send negative float value
thanks

(deleted)

it doesn't work like this when you add the '-42' the receiver receive a wrong value and not -42

Then there is a problem with the receiver.

You're sending ASCII, not numerics. Send:

42 52 50

  • 4 2

Edit: Use a string marker, not character: "-42"

read Robin’s Serial Input Basics and see how to parse input

Thanks

This works fine with negative numbers typed into the serial monitor input text-box:-
(Or sent as '-' 'digit' 'digit' 'digit' 'dp' 'digit'etc)

void setup()
{
    Serial.begin(115200);
}

void loop()
{
    if(Serial.available()>0)
    {
        float fVal=Serial.parseFloat();
        Serial.println(fVal);
    }
}

If you're sending from another Arduino, you can convert a float, (negative or positive), to a C string and send it like this:-

void setup()
{
    Serial.begin(115200);

    float fVal = -238.3;
    char buffer[7];
    dtostrf(fVal, 0, 1, buffer);   // dtostrf(val, width, precision, buffer);
    
    Serial.println(buffer);
}

void loop(){}

Make sure the buffer is large enough to hold all digits, a '-', the decimal point and an extra terminating zero, ('\0').