Article View: comp.text
Article #48Re: Rounding function in c
From: Kendall Bennett
Date: Thu, 30 Jul 1992 01:53
Date: Thu, 30 Jul 1992 01:53
29 lines
1721 bytes
1721 bytes
theo@rascal.UUCP (1472) writes:
>> Does anyone out there have a rounding function for ANSI 'C', I am
>>trying to do some financial applications, and badly need a rounding
>>function.
This must be an FAQ, but you can do it with a simple macro or C++ inline
function:
#define ROUND(x) (floor((x) + 0.5))
or
inline double round(double x)
{
return floor(x + 0.5);
}
Note that this is universal, and works correctly for both the positive AND
negative cases of x.
+------------------------------------------+-------------------------------+
| Kendall Bennett, | Internet: |
| Advanced Computer Graphics Centre, | kjb@godzilla.cgl.citri.edu.au |
| Royal Melbourne Institute of Technology, | rcskb@minyos.xx.rmit.oz.au |
| Victoria, AUSTRALIA. | |
+------------------------------------------+-------------------------------+
| CoSysop (Bossman), PC Connection Australia: +61 3 688 0909 |
+--------------------------------------------------------------------------+
Technical Details
Message-ID:
<kjb.712461189@godzilla.cgl.citri.edu.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!mips!sdd.hp.com!usc!rpi!batcomputer!munnari.oz.au!bruce.cs.monash.edu.au!goanna!minyos.xx.rmit.oz.au!kjbReferences:
<1992Jul14.181421.24591@mr.med.ge.com> <1992Jul16.232926.4740@rossinc.com> <451@rascal.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!mips!sdd.hp.com!usc!rpi!batcomputer!munnari.oz.au!bruce.cs.monash.edu.au!goanna!minyos.xx.rmit.oz.au!kjb From: kjb@cgl.citri.edu.au (Kendall Bennett) Newsgroups: comp.text Subject: Re: Rounding function in c Message-ID: <kjb.712461189@godzilla.cgl.citri.edu.au> Date: 30 Jul 92 01:53:09 GMT References: <1992Jul14.181421.24591@mr.med.ge.com> <1992Jul16.232926.4740@rossinc.com> <451@rascal.UUCP> Sender: usenet@minyos.xx.rmit.oz.au (Njuiz noveles nova newes) Organization: RMIT Advanced Computer Graphics Centre, CITRI, Melbourne Lines: 29