Logo Search packages:      
Sourcecode: inkscape version File versions

double Geom::decimal_round ( double const   x,
int const   places 
) [inline]

Returns x rounded to the nearest places decimal places.

Implemented in terms of round, i.e. we make no guarantees as to what happens if x is half way between two rounded numbers.

Note: places is the number of decimal places without using scientific (e) notation, not the number of significant figures. This function may not be suitable for values of x whose magnitude is so far from 1 that one would want to use scientific (e) notation.

places may be negative: e.g. places = -2 means rounding to a multiple of .01

Definition at line 76 of file utils.h.

References round().

Referenced by Geom::Point::round().

    //TODO: possibly implement with modulus instead?
    double const multiplier = std::pow(10.0, places);
    return round( x * multiplier ) / multiplier;

Generated by  Doxygen 1.6.0   Back to index