Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2008-04-23 11:48:32


Fernando Cacciola wrote:
>> I just discovered (by debugging instead of reading :-() that a
>> numeric_cast from a floating to an integral type always truncates by
>> default, that is, 26.99999 is casted to 26.
>> Is there a way to tell numeric_cast to use the nearest integer?
>> Of course I can add 0.5 to my value and cast afterwards but that's
>> definitely ugly.

If you're happy to use SVN Trunk, then you might want to take a look at the
trunc and round family of functions here:
http://svn.boost.org/svn/boost/trunk/libs/math/doc/sf_and_dist/html/math_toolkit/special/rounding.html

Cheers, John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net