Re: Rounding a floating point number



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

.



Relevant Pages

  • Re: XQ and ->Qpi bug on large X
    ... you shouldn't be rounding to only two digits ... I am trying to make a similar point here about rounding; ... and round it, ... prior to using the input values in calculations. ...
    (comp.sys.hp48)
  • Re: My Completed RATECRYPT() function included below
    ... I was interested because most rounding functions do not round in an unbiased manner. ... I have seen various reports of clipper rounding problems but there are many different rounding methods and clipper chose a common one. ... The gaussian method (an unbiased estimator) gives the same answer you would get using a standard c compiler and printed with printf. ...
    (comp.lang.clipper)
  • Re: XQ and ->Qpi bug on large X
    ... plot of all specific values resembling a "normal distribution" ... we should round each value ... which fails if we start computing "mean square" ... the moment we begin rounding data, we make the data less reliable ...
    (comp.sys.hp48)
  • Re: Rounding errors
    ... DO NOT add up the rounded amounts for the ... That's what I meant by "rounding intermediate results." ... Since we, as receiver of the report, lack access to unrounded detail, ... >thousands that do add up is the 'round and forward' that I described. ...
    (comp.lang.cobol)
  • Re: Mike W. Corner
    ... tender and will round up in half-a-heartbeat, you can spin them out. ... Rounding up is one of your two primary defenses against a broach. ... Having a plan sure helps. ...
    (rec.motorcycles.dirt)