How do I round off my data sensor in two decimal places?

#1
  1. My goal is: to round off my sensor data in to two decimal places in javascript

  2. My actions are:

let temp = dht.getTemp();
let hum = dht.getHumidity();

Timer.set(10000 /* milliseconds */ , Timer.REPEAT, function () {
                       let msg = JSON.stringify({
                       con: GCP.isConnected(), // enable to check connectivity to GCP
                       id: Cfg.get('device.id'),
                       hum: hum.toFixed(2),
                       temp: temp.toFixed(2)
  });
   print(topic, '->', msg);
  MQTT.pub(topic, msg, 1);
}, null);
  1. The result I see is: [Nov 4 10:25:31.498] MJS callback error: type error
    [Nov 4 10:25:41.498] at init.js:46

  2. My expectation & question is: Instead of the output is “temp: 29.700000”, I want it like this “temp: 29.00”

#2

There is no toFixed in mJS.