7 Replies Latest reply on May 22, 2017 11:50 AM by abenitez_2028101

    Print a float value on LCD with 3 decimals

    abenitez_2028101

      Hi guys. I am doing a project for the University that deals with PSoC 1, specifically CY8C27443-24 PXI. Here is the thing, I'm trying to print a float value on a 16x2 LCD with LCD_PrString() function, this function accepts as parameter a char *. Here is an example of how I print in the LCD.

         

      float var_float=1.235456829;    // this is the result of a mathematical operation, I do not know the exact value, this is an example.

         

      char* var=ftoa(var_float, &status);   // this function converts from float to char* in order to show the number on the LCD

         

      LCD_1_PrString(var);  // this is the function for printing on the LCD.

         

      The problem is that the number displayed on the LCD has several decimals and I want to round it only in 2 or 3 decimals. The result I have in the LCD is, for example: 15,12399999999 (always with a lot of 9s at the end of the number). How Can I solved this, I've tried with several examples from internet and it does not work.

         

      Thanks in advanced and sorry for my English, I am from Cuba.