Function convert real number to string

Started by kngoc, June 21, 2016, 12:36:05 AM

Previous topic - Next topic

kngoc

In pic-maxi-web, temperature values are convert from integer to string by funtion: itoa(temperature, TempString);
But I want to show temperature values are real numbers (ex.: 32.6).
I set the temperature variable is a float and use funtion RTOS, but there is no function RTOS in Helpers.c
How to solve this problem?
Looking forward to your help. Thank you.

JohnS

Various C functions exist so use the one you want.

John

kyrk.5

Hi,

I think this might be convenient:
http://www.cplusplus.com/reference/cmath/modf/

For PIC usually there is a float/double version of the function also available. After the conversion the int part can be casted to integer, the fraction part can be *10 and then converted to integer. That way you get 88.8
88.88 Is more tricky. You need to *10 and then convert it to integer and print with %2.2u to see the leading zeros. That way you get 88.08 also.

By the way, is sprintf not able to handle float numbers directy?

kngoc

I want to display on the Web page (WebPages2 - index.htm - Temperature:?) by command: <p> Temperature: <span id = "temp0" style = "font-weight: normal">? </ Span> </ p>, not the print command.
Thank you for your feedback.




































I want to display on the Web page (WebPages2 - index.htm - Temperature:?) By command: <p> Temperature: <span id = "temp0" style = "font-weight: normal">? </ Span> </ p>, not the print command.
Thank you for your feedback.









I want to display on the Web page (WebPages2 - index.htm Temperature:?) By command: <p> Temperature: <span id = "temp0" style = "font-weight: normal">? </ Span> </ p>, not the print command.
Thank you for your feedback.









I want to display on the Web page (WebPages2 - index.htm Temperature:?) By command: <p> Temperature: <span id = "temp0" style = "font-weight: normal">? </ Span> </ p>, not the print command.
Thank you for your feedback.