Send float using json

1

I am trying to send a number with a comma through JSON to save them in a MySQL database through a api rest created in node js.

Endpoint code

router.post('/', (req, res) => {
    const sensorData = {
        id: null,
        temperatura: req.body.temperatura,
        humedad: req.body.humedad,
        indice_calor: req.body.indice_calor,
        fecha: null,
    };

Sensor.insertMetric(sensorData, (err, data) => {
    if(data && data.insertId){
        res.status(200).json({ 
            success: true,
            data: data
        });
    } else{
        res.status(500).json({
            success: false
        });
    }
});

JSON that sent

{
    "temperatura": 2.3,
    "humedad": 2.3,
    "indice_calor": 2.3
}

However, in the database the values are stored as 0.99

    
asked by Emanuel Cortez 04.02.2018 в 21:13
source

1 answer

0

If the error is in the data entry, you can try with Number.parseFloat(req.body.temperatura) . At this point I would do console.log to know that you are really collecting.

In the case that it is in database, perhaps it is not creating the insert well or the rank of the column is small.

    
answered by 04.02.2018 в 22:27