SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By boily
#65228
I'm trying to do a sprintf and I'm only getting constent 0.00000 reading from my analog imput....

What am I doing wrong ??
Is there another way to print decimals on my LCD ?

Thanks :)
Code: Select all
	
int8 x;
float g;
char msg   [10];
char espace [21]; 

x = read_adc(); 					
g = (x-110)*(1/36);					
sprintf(msg, "%f", g);
strcpy(espace, "                   ");  
strcat(msg, espace);	 			
delay_ms(500);
ecrire_chaine(msg);

By jasonharper
#65243
boily wrote:g = (x-110)*(1/36);
This expression always has a value of zero.

(1/36) is always zero, because both operands are integers, and the operation performed is therefore integer division. Try something like (1.0f/36) or (1/36.0f) to force the use of floating-point division.