Skip to Content.
Sympa Menu

freetds - RE: tds_money_to_string()

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Brian Bruns <camber AT ais.org>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: RE: tds_money_to_string()
  • Date: Mon, 9 Oct 2000 18:47:36 -0400 (EDT)


Unfortunately, this won't work on platforms without 'long long'. Looks
like you might be on Alpha? (little endian + 64bit?)

Here's a more generic fix for all numerics with values < scaling (which
is the broader problem here).

static char *array_to_string(unsigned char *array, int scale, char *s)
{
int top, i, j;

- for (top=MAXPRECISION-1;top>=0 && !array[top];top--);
+ for (top=MAXPRECISION-1;top>=0 && top>scale && !array[top];top--);

if (top == -1)


Cheers,

Brian

On Mon, 9 Oct 2000, Brandon M. Reynolds wrote:

> The tds_money to string is broken for money values between 0.10 and 0.00.
> This function should be a lot better.
>
> char *tds_money_to_string(TDS_MONEY *money, char *s)
> {
> /* note: byte order might be different on a big-endian machine. please check
> */
>
> long long longword = (long long)money->mnyhigh<<32|(long long)money->mnylow;
> if(longword%10000) { /* does this have a decimal portion? */
> char *t;
> if(longword < 0) {
> *s++='-';
> longword=-longword;
> }
> t=s+sprintf(s, "%lld.%04lld", longword/10000,
> longword%10000)-1;
> while(*t == '0') /* strip trailing 0's */
> *t--='\0';
> } else
> sprintf(s, "%lld", longword/10000);
>
> return s;
> }
>
> Brandon M. Reynolds Ph: (330) 644-3059
> Systems Engineer Fax: (330) 644-8110
> Commercial Timesharing Inc. Email: bmr AT comtime.com
>





Archive powered by MHonArc 2.6.24.

Top of Page