LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-29-2007, 03:30 PM   #1
C_to_be
LQ Newbie
 
Registered: Oct 2007
Posts: 1

Rep: Reputation: 0
Converting float to ascii in C


Hi All:

I am using the IDE in CodeWarrior MPC555 V8.1. I used the atof function to convert a decimal input value from ascii to float.

Now, I am looking for a way to convert a float value to ascii for display. Unfortunately, the MPC555 does not have ftoa functionality.

I am not fluent in C, so any suggestions would be most appreciated!

Thanks,
C_to_be
 
Old 10-29-2007, 03:47 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by C_to_be View Post
Hi All:

I am using the IDE in CodeWarrior MPC555 V8.1. I used the atof function to convert a decimal input value from ascii to float.

Now, I am looking for a way to convert a float value to ascii for display. Unfortunately, the MPC555 does not have ftoa functionality.

I am not fluent in C, so any suggestions would be most appreciated!

Thanks,
C_to_be
char foo[32];
sprintf(foo,"%f",some_float_val);
 
Old 10-29-2007, 06:41 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by BrianK View Post
char foo[32];
sprintf(foo,"%f",some_float_val);
This can be safer (although it is highly unlikely to have a 32-character decimal representation for a float, it is helpful to teach novice C programmers to use safe programming practices):
Code:
char foo[32];
snprintf(foo, sizeof(foo), "%f", some_float_val);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting extended ascii (,) in bash script Hko Programming 4 12-29-2012 03:42 AM
ASCII to float lucky6969b Programming 3 12-15-2005 02:52 AM
ASCII to float calculator (FOC) lucky6969b Linux - General 1 12-14-2005 11:42 PM
Converting int to float? pirate_pete Programming 5 09-15-2005 02:00 AM
Converting ASCII to Binary? Darx Linux - Software 0 04-08-2004 10:43 AM


All times are GMT -5. The time now is 08:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration