www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/28/18:23:29

From: "Arthur" <arfa AT clara DOT net>
To: <djgpp AT delorie DOT com>
Subject: RE: Round function?
Date: Wed, 28 Oct 1998 23:18:44 -0000
Message-ID: <000301be02c9$4e89fa60$d24e08c3@arthur>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
Importance: Normal
In-Reply-To: <36374585.CADABD29@mindspring.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp AT delorie DOT com

> Is there a functionf or rounding off real numbers when casting to
> integers or will a normal type cast do the trick? TIA

Casting a float to an integer will always round down. So 1.1, 1.4, 1.6, 1.8
will all return 1 when rounded down.

Simple solution: add 0.5 to the figure, then cast. So 1.1 and 1.4 will
return 1; 1.6 and 1.8 will return 2.

James Arthur
jaa AT arfa DOT clara DOT net
ICQ#15054819

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019