Topic: Why is there no standard rounding function?
Author: do-not-spam-benh@bwsint.com (Ben Hutchings)
Date: Fri, 12 Sep 2003 15:58:22 +0000 (UTC) Raw View
In article <b_P7b.23593$AU.1096140@twister.southeast.rr.com>,
"Joe Gottman" wrote:
> Why is there no standard function that will round a floating
> point number to a given number of decimal places.
There is - std::sprintf.
> We have floor() and ceil() to rounding to integers, but there
> does not seem to be any standard way to do decimal rounding,
> which is a very common task.
This would require the use of a decimal floating-point type.
However, the standard does not require the use of any particular
base, and most implementations use binary floating-point types
which cannot represent most decimal fractions precisely. One
must instead convert to a decimal string representation.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net (James Kuyper)
Date: Mon, 15 Sep 2003 17:10:43 +0000 (UTC) Raw View
do-not-spam-benh@bwsint.com (Ben Hutchings) wrote in message news:<slrnbm3pmj.3o.do-not-spam-benh@tin.bwsint.com>...
...
> This would require the use of a decimal floating-point type.
> However, the standard does not require the use of any particular
> base, and most implementations use binary floating-point types
> which cannot represent most decimal fractions precisely. One
> must instead convert to a decimal string representation.
An alternative approach would be to use scaled integers.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jgottman@carolina.rr.com ("Joe Gottman")
Date: Thu, 11 Sep 2003 16:35:06 +0000 (UTC) Raw View
Why is there no standard function that will round a floating point number
to a given number of decimal places. We have floor() and ceil() to rounding
to integers, but there does not seem to be any standard way to do decimal
rounding, which is a very common task.
Joe Gottman
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]