Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By swilson
#57953 Using a NodeMCU1.0 board with a BME280 for a little project. The BME280 returns values for temp, humidity, and dew point with decimals such as 74.14 F. I want to trim the output of that so it just shows 74 F or at least 74.1 F. Does anyone know how I can do that? I looked throught eh BME280-master library I am using but no help. Thanks.
User avatar
By eketjall
#57990 Not an ESP8266 issue but anyway;

If you want to store the output in a char array:
Code: Select allfloat val = 74.14;
char array[10];
sprintf(array, "%.1f", val);    // %.1f  for 1 decimal, %.2f for 2 decimals etc
// array contains your "new" value as a char array.


if you just want an integer: (just truncates, no rounding)
Code: Select allfloat val = 74.14;
int new_val = (int) val;



if you just want to print to serial:
Code: Select allfloat val = 74.14;
int n = 1 // number of decimals
Serial.print(val,n);