I have an application that is basically a calculator.
It takes user input, runs some floating point equations
and places the result in a Field control on a form.
I used the float to string conversion from the FAQ
(attached below). However, it wants to keep the
numbers in exponential notation when I assign
them to a string. My output will always be between
0 and 1 (ie 0.98)
How do get this floating point number into a
string in a custom format?
TIA,
Paul Fearn
[EMAIL PROTECTED]
NEW: How do I convert a float or
double to a string? Alternately, how
do I convert a string to a float or
double? (9/16/98)
The current implementation of the Palm OS
(Version 3.0) does
not have direct support to convert between
floats/doubles and
strings. You can, however, use the NewFloatMgr.c
FlpFToA
and FlpAToF functions to convert between the data
types.
Because FlpFToA and FlpAToF use the FlpDouble
data type,
you have to use an FlpCompDouble datatype to
convert
between your float/double and an FlpDouble. Below
is a code
example that shows how to properly use
FlpCompDouble.
Note that older versions of the Palm OS and
Codewarrior for
Palm Computing platform required that you use
special data
types for handling floating point numbers. As of
Palm OS 2.0
and Codewarrior Release 4, you can use the
standard C float
and double datatypes.
Also note that you will need to include the
NewFloatMgr.h
header file in your project in order to use
FlpFToA and
FlpAToF.
RectangleType theRect;
FlpCompDouble theCompFloat;
char theString[80];
float theFloat;
// Convert a string to a float
theCompFloat.fd = FlpAToF( "12345.678" );
theFloat = theCompFloat.d;
// Convert a float to a string
theCompFloat.d = 1234.678;
FlpFToA( theCompFloat.fd, theString );