[LCP]Rounding questions

Andrew Weaver Andrew.Weaver at tecnomen.fi
Thu Sep 5 20:51:05 UTC 2002


Chuck, this gets weirder...

try this...

double a = 390;
printf("\nf = %f, e = %e, g = %g", a,a,a);
printf("\nf = %f, e = %e, g = %g", round((double)390), round((double)390),
round((double)390));

On Thursday, September 05, 2002 1:25 PM, Chuck Martin
[SMTP:nrocinu at myrealbox.com] wrote:
> On Thu, Sep 05, 2002 at 11:08:12AM +0100, Vincent Penquerc'h wrote:
> > > Why is it rounding 390.0 and getting 2.896811?
> > 
> > Dunno. Try
> > 
> > double round(double x)
> > {
> >   return floor(x+0.5);
> > }
> 
> That returns "390.000000", and is similar (but not exactly the same) to
> what I was doing before that had a strange bug (apart from the fact that
> that would have to be modified to work with negative numbers).
> 
> Chuck
> 
> 
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List




More information about the linuxCprogramming mailing list