Discussion:
Converting a char sequence to a float and converting it back
(too old to reply)
David
2006-10-17 19:50:57 UTC
Permalink
I created a NUMERIC MAXCHARS 40 UNDERLINED text field for the GUI.
And I figured out how to get the text inside that text field inside the
Palm C Code.
I seem to only be able to extract it as a char sequence even though it
is NUMERIC.
How can i convert my char sequence into float?
static Char bar[80];

And how can i set it back to a char sequence to then apply it back to a
different text field?
The reason I want to do this is to do some math on the number, then
spit it back out in a different text field.
thanks,
David
David
2006-10-17 20:03:31 UTC
Permalink
I searched this forum already,I found articles about this, but none of
them answered my question.
If you can do this,please tell me how.
Baxter
2006-10-18 01:55:44 UTC
Permalink
Your biggest problem is that Palm doesn't do floats very well.
--
---------------------------------------------------------------------
DataGet® & PocketLog® www.dataget.com
Data Collectors www.baxcode.com
--------------------------------------------------------------------
Post by David
I created a NUMERIC MAXCHARS 40 UNDERLINED text field for the GUI.
And I figured out how to get the text inside that text field inside the
Palm C Code.
I seem to only be able to extract it as a char sequence even though it
is NUMERIC.
How can i convert my char sequence into float?
static Char bar[80];
And how can i set it back to a char sequence to then apply it back to a
different text field?
The reason I want to do this is to do some math on the number, then
spit it back out in a different text field.
thanks,
David
Ciaran Keating
2006-10-18 22:57:36 UTC
Permalink
Post by David
I created a NUMERIC MAXCHARS 40 UNDERLINED text field for the GUI.
And I figured out how to get the text inside that text field inside the
Palm C Code.
I seem to only be able to extract it as a char sequence even though it
is NUMERIC.
Hi David,

The NUMERIC parameter means that the text field will accept only the
characters '0' to '9' and the thousands and decimal separator. (Do you
have a copy of the Palm OS Programmer's API Reference?) The OS doesn't do
any string->number conversion for you.
Post by David
How can i convert my char sequence into float?
static Char bar[80];
You'll have to construct the number yourself by parsing the string. Not
quite as trivial as having the OS do it magically for you, but still
trivial nonetheless.


Good luck,
Ciaran
--
Ciaran Keating
Amadán Technologies Pty Ltd
David
2006-10-19 00:05:43 UTC
Permalink
well do you know of a nice little function out there that will convert
it for me?
I dont understand all of the funtimentals of C code to write the
function myself
Post by Ciaran Keating
Post by David
I created a NUMERIC MAXCHARS 40 UNDERLINED text field for the GUI.
And I figured out how to get the text inside that text field inside the
Palm C Code.
I seem to only be able to extract it as a char sequence even though it
is NUMERIC.
Hi David,
The NUMERIC parameter means that the text field will accept only the
characters '0' to '9' and the thousands and decimal separator. (Do you
have a copy of the Palm OS Programmer's API Reference?) The OS doesn't do
any string->number conversion for you.
Post by David
How can i convert my char sequence into float?
static Char bar[80];
You'll have to construct the number yourself by parsing the string. Not
quite as trivial as having the OS do it magically for you, but still
trivial nonetheless.
Good luck,
Ciaran
--
Ciaran Keating
Amadán Technologies Pty Ltd
Ciaran Keating
2006-10-19 14:43:39 UTC
Permalink
Post by David
well do you know of a nice little function out there that will convert
it for me?
I dont understand all of the funtimentals of C code to write the
function myself
Post by Ciaran Keating
You'll have to construct the number yourself by parsing the string. Not
quite as trivial as having the OS do it magically for you, but still
trivial nonetheless.
Not trying to be funny or rude or anything, but... if you can do anything
at all in C then you can write this function.

Or maybe you're programming in some other language? In which case, if you
can figure out how to link a C function with an app written in another
language, then you can figure out how to write this function.

In fact, if you can figure out how to install the development tools for
the Palm and get them working, then you've got more than what it takes to
write this function :-)

Go on - give it a try!
--
Ciaran Keating
Amadán Technologies Pty Ltd
Tim Oltrogge
2006-10-19 21:14:03 UTC
Permalink
How about the atof() function?

Then use sprintf() to turn the floating point result back to a string.
Baxter
2006-10-20 01:49:54 UTC
Permalink
Palm does not have a -native- atof() function.

There are a number of ways to go:
- use something like Codewarrior's MSL library
- use the Palm FloatManager (FlpFloat) functions
- write your own routines

or do like a lot of Palm programmers do and use integer math - and fake the
decimal point.
--
---------------------------------------------------------------------
DataGet® & PocketLog® www.dataget.com
Data Collectors www.baxcode.com
--------------------------------------------------------------------
Post by Tim Oltrogge
How about the atof() function?
Then use sprintf() to turn the floating point result back to a string.
Tim Oltrogge
2006-10-20 13:53:57 UTC
Permalink
Post by Baxter
Palm does not have a -native- atof() function.
I've only scratched the surface of programming for the Palm. I downloaded
the cygwin tools and compile my programs using the gcc compiler and its
libraries. I'm using atoi() that way and I *assume* atof() is also available
even though it's not mentioned in the Palm reference manual.
Baxter
2006-10-21 02:58:04 UTC
Permalink
Those are NOT -native- Palm functions.

StrAToI() is native to Palm. If you include the Float Manager, there is a
FplAtoF() for FloatTypes - but it is not supported by the PACE 5.0 feature
set.

In any case, floating point on the Palm leaves much to be desired and most
Palm programmers use integer math - simply store the decimal pt as a UInt8
(or uint8_t).
--
---------------------------------------------------------------------
DataGet® & PocketLog® www.dataget.com
Data Collectors www.baxcode.com
--------------------------------------------------------------------
Post by Tim Oltrogge
Post by Baxter
Palm does not have a -native- atof() function.
I've only scratched the surface of programming for the Palm. I downloaded
the cygwin tools and compile my programs using the gcc compiler and its
libraries. I'm using atoi() that way and I *assume* atof() is also available
even though it's not mentioned in the Palm reference manual.
Loading...