Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion from string to float 1

Status
Not open for further replies.

RobertSBoyle

Programmer
Feb 21, 2001
16
0
0
EU
Hi there,
Has anyone come accross the problem of converting a string to a float and losing the leading zero? This affects the decimal places that is used for calculation of a longitude/latitude position. Is there a simple c function which will stop this from happening (I am using atof at the moment.)

Cheers
R.
 
i believe

float value;
char str_value[12];
sprintf(str_value,"%0f",value) will keep the 0 before the decimal point

Matt
 
Heh, I just tested it and using a plain %f will work fine as well.

Matt
 
The atof function will remove the leading zeros. If U want these things then U have go or other options like writing new functions.

Maniraja S
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top