www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/26/05:38:55

Message-ID: <20010926093422.5514.qmail@web8006.mail.in.yahoo.com>
Date: Wed, 26 Sep 2001 10:34:22 +0100 (BST)
From: =?iso-8859-1?q?Prashant=20TR?= <prash_tr AT yahoo DOT co DOT in>
Subject: Fwd: [LIP] sprintf. I am stumped
To: djgpp AT delorie DOT com
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

I got this program from a friend and I tried this out
on DJGPP. I expected that it would round to the
nearest even number as the ISO standard says (hope I'm
remembering it right), but it doesn't happen so. Any
explanations would be appreciated...

----
> Date: Wed, 26 Sep 2001 11:45:01 +0530
> 
> #include <stdio.h>
> 
> main()
> {
>   double a0=0.00005;
>   double a1=0.11115;
>   double a2=0.22225;
>   double a3=0.33335;
>   double a4=0.44445;
>   double a5=0.55555;
>   double a6=0.66665;
>   double a7=0.77775;
>   double a8=0.88885;
>   double a9=0.99995;
>   char b[10];
> 
>   sprintf(b,"%.4f",a0);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a1);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a2);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a3);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a4);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a5);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a6);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a7);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a8);printf("b=%s\n",b);
>   sprintf(b,"%.4f",a9);printf("b=%s\n",b);
> }
>
------------------------------------------------------
> 
> Output
>
------------------------------------------------------
> b=0.0001
> b=0.1111
> b=0.2223
> b=0.3333
> b=0.4445
> b=0.5555
> b=0.6666
> b=0.7778
> b=0.8889
> b=1.0000
> -----------------------------------------------------

____________________________________________________________
Do You Yahoo!?
Send a newsletter, share photos & files, conduct polls, organize chat events. Visit http://in.groups.yahoo.com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019