# Removal of Decimal Places

Hey,

I’m working on this little project for some fun and I can’t seem to get the unit to work the way I want.

I’m reading from a analog sensor and it appears that my numbers are coming out fine on my HD44780. Except; I have a lot of decimal places! So many in fact it erases the other information on the screen.

How can I remove these places? Thanks.

You have a bug in your sketch, the analogue ADC returns an integer value between 0 and 1023, there are no decimal places. If you post your sketch using the code button (#), we’ll maybe be able to put you right.

Well the value 0-1023 is then put into a formula, so a few calculations are done. Could that not yeild a decimal?

Here is parts of my code:

#include <LiquidCrystal.h>

int sensor = 0; //Sets the sensor input to pin 0
int boost = 0; //sets the boost to 0
int sensorval = 0; //sets sensor value to 0
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //sets the pins for the LCD

void loop() {
sensorval = analogRead(sensor); //Polls the sensor for data
boost = ((sensorval*.0049)/5.1+.04/.00369 *.14503774); //converts sensorval

lcd.setCursor(7,0); //sets the cursor position
lcd.print(boost); //prints boost data
lcd.setCursor(11,1);

Thats the quote button

Since your calculations are using integer variables, all they can return is integers. As far as I’m aware the lcdprint function can only handle strings, you need to convert the number to a string before displaying it.
Do some looking up of “sprintf”

Sounds like your problem is more to do with leading zero suppression than decimals.
If your first number to display occupies 4 digits, but subsequent ones are three digits, then the fourth digit may not be being erased.

You could try printing trailing spaces, though it is visually better (IMO) to print leading spaces.

Sorry, I use the sketch program to copy/paste and it did the quote on it’s own.

I’m not sure I understand what you mean. It does print, just too many decimals. I think.

Thats the quote button Wink

Just to get rid of this misunderstanding. OP probably selected ‘copy for forum’ from the IDE. Then there is nice syntax coloring but has to be a ‘quote’. I’ve posted about this in the software Bugs & Suggestions board about this http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1259327352

Sorry for being off topic.

Jeroen

edited

AWOL…

I did account for the numbers not being erased. I have a line where it prints blank spaces with a If statment. Once it drops below 10.

I should have said. I want this to only display to the tens. It also should max out around 35-40.

I was wrong about it only being able to print strings.

what happens if you specify a base for the value ?
as in :

``````lcd.print(boost,DEC); //prints boost data
``````

This sounds strange, but the DEC command…worked. It appears to be working ok.