Hi..
I have problems about converting from double to ascii when digit numbers
exceed 10.
otherwise it runs okey.
FlpFToA( 12345678901, s)
s==> 1.2345679e10
However the s value must be 1.23456789e10
does anyone know of the solution for this problem?
Regards
Short doubletoascii(const double x, CharPtr s)
{
char temp[80];
char thousand_separator, decimal_separator;
if (s == NULL)
return 0;
// Use the OS to convert the double to ASCII.
FlpCompDouble theCompdouble;
theCompdouble.d = x;
if (FlpFToA( theCompdouble.fd, s)) {
StrCopy(s, "Overflow");
return StrLen(s);
}
// De-localize the number string so that it uses U.S. conventions
LocGetNumberSeparators ((NumberFormatType)
PrefGetPreference(prefNumberFormat),
&thousand_separator, &decimal_separator);
StrDelocalizeNumber (s, thousand_separator, decimal_separator);
Short string_length = StrLen(s);
Short e_position = string_length - 3;
if (s[e_position] == '-')
e_position--;
Long exponent = StrAToI( & s[e_position + 1] );
// Wipe out the "e[-]zz" at the end of the string
Short i = e_position;
while (s[i] != 0) {
s[i] = 0;
i++;
}
string_length = e_position;
Short decimal_position = 1;
if (s[decimal_position] != '.')
decimal_position++;
if (exponent != 0) {
// Delete the decimal point, moving all other numbers forward one.
for (i = decimal_position; i < string_length - 1; i++)
s[i] = s[i + 1];
string_length--;
}
if (exponent < 0) {
// If exponent is negative, add zeros to the front.
StrCopy(temp, "0.0000000000000000000000000000000");
temp[1 - exponent] = 0;
StrCat(temp, s);
StrCopy(s, temp);
string_length += 1 - exponent;
} else if (exponent > 0) {
decimal_position += exponent;
for (i = string_length; i > decimal_position; i--)
s[i] = s[i - 1];
s[decimal_position] = '.';
string_length++;
}
// Remove trailing zeroes.
i = string_length - 1;
if ( (s[string_length] != '.') && (i > 0))
{
while ((s[i] == '0') && (i > 0)) {
s[i--] = 0;
string_length--;
}
}
else
string_length++;
if (string_length - decimal_position > 3) {
if (s[decimal_position + 3] > '4')
s[decimal_position + 2]++;
for (i = decimal_position + 3; i < string_length; i++)
s[i] = 0;
}
// Remove trailing garbage, if any
while (((s[string_length - 1] < '0') || (s[string_length - 1] > '9'))
&& (string_length > 0))
s[--string_length] = 0;
// Re-localize the number, and return the length.
LocGetNumberSeparators ((NumberFormatType)
PrefGetPreference(prefNumberFormat),
&thousand_separator, &decimal_separator);
StrLocalizeNumber (s, thousand_separator, decimal_separator);
// Recalculate string length in case it was changed during localization.
return StrLen(s);
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.381 / Virus Database: 214 - Release Date: 02.08.2002
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/