Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!uw-beaver!blake!oregon!michelbi From: michelbi@oregon.uoregon.edu (Michel Biedermann) Newsgroups: comp.lang.c Subject: Answer to rounding any number to a given decimal point Message-ID: <3009@oregon.uoregon.edu> Date: 23 May 89 06:18:17 GMT Organization: University of Oregon Lines: 13 Here is the most elegant answer to the problem of rounding-off an arbitrary number to an arbitrary decimal level. #define round(x,y) ((x < 0.0F? ceil((x)/(y)-.5F)*(y) : floor((x)/(y)+.5F)*(y))) round(1.5555,.1) will return 1.6 round(-1.555,.1) will return -1.6 round(.502,.01) will return .50 Credit is due to Steve Emmerson (steve@umigw.miami.edu). Thanks Steve... Michel Biedermann U. of Oregon