I found useful to keep currency data packed in long. It's especially
useful if you want to synchronize your data with desktop application
because synchronization of integral formats is pretty ease.
Here is h-file that is used in my application for such tasks. You can
include this file both into Palm and Win32 applications:
#ifndef __CURRENCY_H__
#define __CURRENCY_H__
typedef long CurrencyType;
typedef CurrencyType* CurrencyPtr;
#define makeCurrency(intPart, realPart) ((intPart) * 100 + (realPart))
#define currencyAbs(currency) ((currency) < 0 ? -(currency) :
(currency))
#define currencyInt(currency) ((currency) / 100)
#define currencyReal(currency) ((currency) % 100)
#define currencyToFloat(currency) ((float)(currency) / 100.0f)
#define currencyToDouble(currency) ((double)(currency) / 100.0)
#define currencyAdd(currency1, currency2) ((currency1) + (currency2))
#define currencySub(currency1, currency2) ((currency1) - (currency2))
#define currencyMul(currency1, currency2) ((currency1) * (currency2) /
100)
#define currencyDiv(currency1, currency2) (100 * (currency1) /
(currency2))
#define realToCurrency(real) ((CurrencyType)((real) * 100.0))
#define intToCurrency(_int) ((CurrencyType)((_int) * 100))
#ifdef WIN32
#define currencyToString(currency, string) wsprintf(string,
_T("%ld.%02ld"), currencyInt(currency), currencyReal(currency))
#define stringToCurrency(string) realToCurrency(atof(string))
#else
#define currencyToString(currency, string) StrPrintF(string,
"%ld.%02ld", currencyInt(currency), currencyReal(currencyAbs(currency)))
#define stringToCurrency(string) _d_dtoi(_d_mul(FlpAToF(string),
_d_itod(100)))
#endif
#endif
> -----Original Message-----
> From: [EMAIL PROTECTED]
[mailto:bounce-palm-dev-
> [EMAIL PROTECTED]] On Behalf Of Mahesh Salian
> Sent: Tuesday, April 23, 2002 8:37 AM
> To: Palm Developer Forum
> Subject: Floating point problem
>
> Hi
>
> I am using Code warrior IDE with C compiler.
> Can i use float in the data structure . Is it possible to pack and
unpack
> this structure if i use float.
> The flat files which i sync with my application hv the decimal digits
> (for
> eg. Price = 10.55 ). Can anybody suggest how could i capture this
decimal
> numbers in my structure and also able to pack it.
>
> TIA,
> Mahesh
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/