# Lcd should not display 001% i want to display 1%

Status
Not open for further replies.

#### zalmay

##### Newbie level 4
Can some one please help me out i am working on a pic micro controller project.i am new to controller so i have a problem

i want the lcd to show me 1 % instead of showing 001% or 10% instead of showing 010% and so on.

I want the lcd not to display any zero on left hand side.

#### ckshivaram

compare all the 3 digits after conversion and compare left 2 digits with 0. if it is zero then dont print it..

#### saeed_pk

##### Full Member level 4
how do u convert your integer data to ASCII String
if you use printf or sprintf() it replaces zeros with space so you will not see 010 %

thunderboympm

### thunderboympm

points: 2

#### zalmay

##### Newbie level 4
thanks saeed brother;
i am converting integer by adding 48 to the data hence getting ASCII value.i havn't used printf rather i have used built in command LCD_OUT in micro-c.

#### zalmay

##### Newbie level 4
thanks
i am using the if statement but it is not working. i have coded in micro-c something like;

if(parameter[0]==0) then ..... else LCD_OUT(row,col,parameter) the if condition never becomes true else statment is executed all the times.

---------- Post added at 07:35 ---------- Previous post was at 05:55 ----------

hi everyone;
finally i got the statement right it is like
if(parameter[0]==48) then... 48 because parameter is an ASCII value and 48 in ASCII for 0 in decimal so condition becomes true now.but another problem is that parameter has three values like parameter[0],parameter[1],parameter[2].now i want only the ascii value of parameter[2] to display i m using
LCD_OUT(row,col,parameter[2]) but it gives a blank value.
any solution for this problem???

#### alexan_e

I'm not sure how LCD_OUT works in your compiler, maybe it expects a null terminated string, in that case you need to make an array of four char and set the last one to null (parameter[3]=0)
And you code is not clear, I understand that you add value 48 to convert a number to the ascii representation but I can't understand if you are doing something wrong.

Alex

#### thunderboympm

##### Full Member level 5
thanks
i am using the if statement but it is not working. i have coded in micro-c something like;

if(parameter[0]==0) then ..... else LCD_OUT(row,col,parameter) the if condition never becomes true else statment is executed all the times.

---------- Post added at 07:35 ---------- Previous post was at 05:55 ----------

hi everyone;
finally i got the statement right it is like
if(parameter[0]==48) then... 48 because parameter is an ASCII value and 48 in ASCII for 0 in decimal so condition becomes true now.but another problem is that parameter has three values like parameter[0],parameter[1],parameter[2].now i want only the ascii value of parameter[2] to display i m using
LCD_OUT(row,col,parameter[2]) but it gives a blank value.
any solution for this problem???
dear friend,
that is all berden. The better option i suggest is using sprintf() function. That function will do all you want
Syntax
unsigned char temp[6]
sprintf(tmp,"%d", <the integer value>);
lcd_out(tmp);

#### alexan_e

The better option i suggest is using sprintf() function
Easier is not always better, sprintf may be easier but it also takes a lot of space, it is not a bad idea to learn to use other way especially to convert a 3 digit number to a string.

Alex

#### ZASto

Code:
Select Value
Case > 99
Print At Row, Col, Dec Value, "%"

Case > 9
Print At Row, Col, " ", Dec Value, "%" ' One leading space

Case Else
Print At Row, Col, "  ", Dec Value, "%" ' Two leading spaces
End Select
This easy transcribed to any programming language such as C or Pascal.

The given code is "quick and dirty" one written in Proton+. It assumes that the "%" sign mis at the fixed position.

#### thunderboympm

##### Full Member level 5
Easier is not always better, sprintf may be easier but it also takes a lot of space, it is not a bad idea to learn to use other way especially to convert a 3 digit number to a string.

Alex
i agree with that, i think O/P is more important than the memory. Right?

Status
Not open for further replies.