When I was first getting into using floating point math in my app, a lot of
developers told me to just create my own float manager. I attempted to use
the built-in float support anyway, but I became exasperated by its lack of
precision. I finally gave in and wrote my own functions using Ints. I only
require precision to 2 decimal places, and values ranging from
approximately -1,000,000 to +1,000,000, so I was able to use Long Ints with
two extra digits at the end. For example, the number 1 is stored as 100, and
12.34 is stored as 1234. It works quite well, but it took me a while to code
all the arithmetic operators.
Cheers,
Mark
-----Original Message-----
From: Freeman, Barry <[EMAIL PROTECTED]>
To: Palm Dev List (E-mail) <[EMAIL PROTECTED]>
Date: Thursday, August 26, 1999 4:00 AM
Subject: Float question (newbie)
>Having just got back into C I'm trying to write a simple app for the palm.
>
>Basically it's a mileage calculator. Simple form with 2 edit fields and a
>button.
>
>Litres goes in the first field, miles goes in the second and the button
>does this:
>
> Convert Litres to gallons
> Divide Miles by Gallons
> set the text of a label to the Miles/Gallon.
>
>So far everything works as far as the event processing goes.
>
>One thing I can't quite get a hold of, is how to get the contents of the
>edit fields and perform the arithmetic on them. They will be floats like
>14.56 litres and 195.8 miles etc.
>
>I can't find the equivalent of strToF in standard C to convert a string to
a
>float. Plus I'm a little unclear as to what I have to do to get the text
out
>of edit fields: I'm assuming it's something like:
>
> Get Handle of Field.Text
> Get Size of Field.Text
> Get CharPointer to Field.Text
> Allocate via MemHandleNew
> Set a New CharPtr to New Memory
> Copy the string from *Field.Text to *Newpointer
>
>It's all a little confusing <G>
>
>BAzz
>