Re: Rounding a floating point number
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Wed, 27 Feb 2008 11:10:32 -0500
user923005 wrote:
CBFalconer <cbfalco...@xxxxxxxxx> wrote:
user923005 wrote:
... snip float rounding discussion ...
You will still have to multiply and divide by powers of 10 and
use floor() to achieve the same thing because the C99 round()
functions round to nearest integer. They do not round to
nearest k decimal places.
Are you claiming that such multiplication and division by 10 is
too complex for the average reader of c.l.c? :-)
No, but I am claiming that using the C99 functions to round to N
digits will take twice as much work as a function that does it
directly, since the multiplication and division by a power of
ten and the floor function are all that is necessary in either
case. And so while you can round to N digits using the C99
rounding functions, it really does not make a lot of sense to do
it that way.
Let me also point out that such rounding is rarely needed. Most of
the time maintaining the original alleged precision and rounding
only the output, via printf, is needed.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: Rounding a floating point number
- From: Bartc
- Re: Rounding a floating point number
- From: user923005
- Re: Rounding a floating point number
- References:
- Rounding a floating point number
- From: jacob navia
- Re: Rounding a floating point number
- From: CBFalconer
- Re: Rounding a floating point number
- From: Ben Pfaff
- Re: Rounding a floating point number
- From: Keith Thompson
- Re: Rounding a floating point number
- From: user923005
- Re: Rounding a floating point number
- From: CBFalconer
- Re: Rounding a floating point number
- From: user923005
- Rounding a floating point number
- Prev by Date: Re: Converting unsigned long to string in C
- Next by Date: Re: Is My Program OK?
- Previous by thread: Re: Rounding a floating point number
- Next by thread: Re: Rounding a floating point number
- Index(es):
Relevant Pages
|