Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!chem.ucsd.edu!tps From: tps@chem.ucsd.edu (Tom Stockfisch) Newsgroups: comp.lang.c Subject: Re: Help needed to round-off a number Message-ID: <478@chem.ucsd.EDU> Date: 21 May 89 01:40:57 GMT References: <2666@oregon.uoregon.edu> Reply-To: tps@chem.ucsd.edu (Tom Stockfisch) Organization: Chemistry Dept, UC San Diego Lines: 22 In article <2666@oregon.uoregon.edu> michelbi@oregon.uoregon.edu (Michel Biedermann) writes: >Is there a C function (user defined or primitive (?)) that will let me >truncate or round-off a number UP TO a certain decimal place. For example >transforming .567 into .6 or -1.502 into -1.5. If speed isn't crucial, use double round( x, sigfigs ) double x; int sigfigs; { char buf[sizeof(double)*20]; /* nice conservative size */ sprintf( buf, "%.*g", x, sigfigs ); sscanf( buf, "%lf", &x ); return x; } -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu