# Multiplying/dividing an integer resulting in a float and displaying on LCD problems

#### Jswale

Joined Jun 30, 2015
121
I have a 10 bit ADC value and I am trying to multiply/divide it and then display the resulting float. The float displays 0.00 and doesn't change, this has something to do with the calculations. perhaps it is because I am trying to multiply/divide a 10 bit binary number and I need to break it down into a decimal?...But I have declared it as an integer so I would have thought the calculations would be fine and the result would be e.g 7.65 and then that is broken into a char ready to be displayed.

Here is the relevant code;

C:
unsigned int ADC_result;
float Power_result_new;
float Power_result;
unsigned char temp[6];
unsigned char temp_p[6];

void main (void)
{
while(1)
{

while(ADCON0bits.GO==1);                            //Waits for conversion to finish
__delay_us(10);

//ADC_result=0xAF;        //Test purposes COMMENT OUT BEFORE BUILD.

lcd_cmd(0x80);                                        //Start of Line 1
lcd_WriteStr("Input V = ");

//At this point both ADC/Power are ready to be displayed, both floats.

lcd_WriteStr(temp);                                    //writes the value (0-5.0V)

lcd_cmd(0xC0);                                        //Starts Line 2
lcd_WriteStr("Power W = ");
sprintf(temp_p, "%4.2f", Power_result);             //Turns float into a ASCII char that can be displayed
lcd_WriteStr(temp_p);                                 //write it

}//while
}    //main

Cheers
JSwale

#### djsfantasi

Joined Apr 11, 2010
7,628
There are several reasons why the result is always zero.

First, you are dividing ADC_RESULT by 1023. The result will always be less than 0. Since all operands are integers, the result will be an integer. Try something like:
Code:
ADC_result_new=(float(ADC_result)*5)/1023)