There is a good article on a similar issue on CPlusPlus.com . An easy solution to your problem should be something like this:
double customRound( double value ) const { return value < 0 ? floor( value ) : ceil( value ); }
The best solution is the one mentioned in the article that uses the template:
//-------------------------------------------------------------------------- // symmetric round up // Bias: away from zero template <typename FloatType> FloatType ceil0( const FloatType& value ) { FloatType result = std::ceil( std::fabs( value ) ); return (value < 0.0) ? -result : result; }
Huppie
source share