- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would
separate fractional part from the integer part.
print the integer part
Rounding to 3 digits precision is done by (fractional part + 0.0005) * 1000 and taking the integer part.
Print decimal point
Convert integer part to string and expand with leading zeroes (0) until the length is 3
Print the string.
Or
Get a CY8CKIT-043 PSoC4-M Prototyping Kit and use sprintf()
Bob