Number of decimals in sketches



  • I don't want the emperature humidity to be as precise as in the sketch which has 2 decimal points.

    So for the humidity i rewrote the sketch as such

      float hum_floa = dht.getHumidity();
      float humidity = round (hum_floa); 
    

    It works but the data is still sent as yy.xx
    Is there a simple way to make it as yy only?


  • Hardware Contributor

    There are probably better ways but:

    hum_floa.remove(temp.indexOf('.') + 2)
    

    Dont know the dht lib, maybe you can set some settings there to recieve without decimals.
    This will not round but just cut/remove the last digits after "."



  • If you use Set to send your temp/hum you can define how many decimals you want:

    MyMessage& set(float value, uint8_t decimals);
    

    For example:

    gw.send(msgTemp.set(temperature, 1));
    

    will send you the value with 1 decimal.

    Reference: here


Log in to reply
 

Suggested Topics

  • 4
  • 26
  • 5
  • 3
  • 1
  • 16
  • 1027

198
Online

9.9k
Users

10.4k
Topics

107.5k
Posts