# decimal to whole number

I’m new here, sorry if this is in the wrong spot or anything. anyway, I have a decimal number that i need to turn into a whole number.

my temp comes out as decimal and i need it to be a whole number. any help would be great, thank you

``````#include <LiquidCrystal.h>
#include <math.h>

double Temp;
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Temp = (Temp - 3);

return Temp;
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

Serial.begin(9600); // serial monitor
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
}

void loop() {

lcd.clear(); //clear screen

// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print second line
lcd.print("Temp");
delay(1000);
}
``````

Do you want to truncate the value or round it?

either way is fine, it dont have to be spot on.

it dont have to be spot on.

Considering the accuracy that you are trying to work to in

``````  Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
``````

I find that quite amusing

lol i just want a simple temp read out, no decimals

Just assign the floating point value to an integer variable. This will truncate.
If you want to round, add a half before the assignment.

how do i do that? sorry im new to this

``````float flt = 123.6745;
int noDec = 0;
noDec = flt; // = 123, truncated
noDec = flt + 0.5; // = 124, rounded
flt = 123.456 ;
noDec = flt + 0.5; // = 123, rounded
``````

lcd.print(Thermister(analogRead(0)), 0); // print temp with zero decimal places

THANK YOU! it worked!

There are four functions to help you with different versions of rounding floats.

Try this snippet of code to spot the differences

``````for (int i= -5; i < 5; i++)
{
float flt = i + 0.45;
int x1 = round(flt);    // rounding
int x2 = ceil(flt);     // round up
int x3 = floor(flt);    // round down
int x4 = trunc(flt);    // remove decimal part
int x5 = flt;           // implicit

Serial.print(x1);
Serial.print('\t');
Serial.print(x2);
Serial.print('\t');
Serial.print(x3);
Serial.print('\t');
Serial.print(x4);
Serial.print('\t');
Serial.print(x5);
Serial.println();
}
``````