Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.os.linux.development.apps Subject: Re: cast double to short problem Date: Wed, 7 Mar 2012 00:30:52 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 28 Message-ID: References: NNTP-Posting-Host: c-24-118-110-103.hsd1.mn.comcast.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1331080252 21748 24.118.110.103 (7 Mar 2012 00:30:52 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 7 Mar 2012 00:30:52 +0000 (UTC) User-Agent: slrn/0.9.9p1 (Linux) Xref: csiph.com comp.os.linux.development.apps:447 On 2012-03-06, Bill M wrote: >> What exactly are you trying to accomplish with the above code? > > I need to interface to another system that does not accept floating > point values. It's interface specifies that certain values are X 10. > other are X 100. > Sounds like maybe what I need is a intermediate round operation? What you were doing was truncating (2.999999999999999 -> 2), and I suspect you want is indeed rounding to the nearest integer FP value followed by the conversion to integer: 2.999999999999999 -> 3.0000000000000 -> 3 $ man round #include i = (short) round(MyDoubleValue * 100.0);