Go Down

### Topic: Converting to decimal on LCD display (Read 2075 times)previous topic - next topic

#### Packhorse

##### Sep 17, 2011, 07:18 am

I need to display a value on a LCD display as a decimal. it will be x/100 and the result will be between 0.00 and 2.00
If I try
lcd.print(x/100);
it does not work and simply show 1

Thanks

#### eddiea6987

#1
##### Sep 17, 2011, 07:46 am
Code: [Select]
`Serial.print(2.0/ 100.0);`
I could print the Arduino logo on a box of cereal and sell it as "Arduin-O's"

#### Packhorse

#2
##### Sep 17, 2011, 07:58 am
Too easy!
So will all maths work like that?

#### eddiea6987

#3
##### Sep 17, 2011, 08:04 amLast Edit: Sep 17, 2011, 08:06 am by eddiea6987 Reason: 1
well that is for floats,
integers will be fine without the decimal.
take a look at the data type section
http://www.arduino.cc/en/Reference/HomePage
I could print the Arduino logo on a box of cereal and sell it as "Arduin-O's"

#### robtillaart

#4
##### Sep 17, 2011, 08:54 am
Two remarks:

Be aware that using floats is relative expensive in term of memory and speed.
Doing it with int 's is possible but takes a few lines of code as you need to "calculate every digit simultaneously.

// you can add a 2nd parameter to the print statement to idicate the number of decimals, default this is 2.
Serial.print(2.0/ 100.0, precission);
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### liuzengqiang

#5
##### Sep 17, 2011, 05:00 pm
OP, say you already have a number between 0 and 200, and you want to display between 0.00 and 2.00, here is what the extra lines rob was referring to:
Code: [Select]
`lcd.print(number/100); // integer partlcd.write('.'); // Print decimal pointif ((number%100)<10) lcd.write('0');// leading zerolcd.print(number%100);`