2
char q[150];
void main(void){

System_Initialization();
UART_Init_2();

 while(1){ 

 double A=23.045610;
 sprintf(q,"%f\r\n",A);    
 UART_Tx_2(q);}}

When I Read value of A its give 23.045410 instead of 23.045610 anyone know why this will happened? i am using PIC18F67k22 controller and Xc8 Compiler

1 Answers1

2

On the PIC18, the data types float and double are the same, and only 32 bits long. That is not enough bits to store more than five or so decimal digits. Therefore you can expect some rounding error at the end of the decimals.

Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75