Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > Convert float to string

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Convert float to string
Moderator:
ANCY

Post Reply
Follow this topic



Convert float to string

Liberty posted on 09 Sep 2011 10:10 PM PST
Member
9 Forum Posts

Hie,

Does anyone know how I can convert a float into a string on the psoc5 (gcc compiler)? I would like to convert floats into strings so that I can display on my GLCD which has library functions for displaying only string types.




Re: Convert float to string

Liberty posted on 09 Sep 2011 05:49 PM PST
Member
9 Forum Posts

I just discovered that the sprintf() function works perfectly for this conversion. The syntax is something like this:

float a = 4.8375;

char a_text[9];

sprintf(a_text,"%f",a);

a_text[4] = '\0';

 

this will return the string 4.84



Re: Convert float to string

Gautam Das posted on 10 Sep 2011 03:50 AM PST
Cypress Employee
742 Forum Posts

Hi Liberty,

 

Thank you for sharing this on the forum !

 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20