From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,efbbbab26bad9cb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-16 03:09:18 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: martin.dowie@btopenworld.com (Martin Dowie) Newsgroups: comp.lang.ada Subject: Re: how to round integers Date: 16 Jun 2003 03:09:18 -0700 Organization: http://groups.google.com/ Message-ID: References: NNTP-Posting-Host: 20.138.254.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1055758158 18871 127.0.0.1 (16 Jun 2003 10:09:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 16 Jun 2003 10:09:18 GMT Xref: archiver1.google.com comp.lang.ada:39227 Date: 2003-06-16T10:09:18+00:00 List-Id: "Cephus�" wrote in message news:... > I am trying to remember the "golden rule" for integer division rounding. > > I am trying to average something (both integers) and I can't remember how to > round without using floating point. > > Like say I am trying to divide 26/3 --- I would get 8 remainder 2 > > but that should round up to 9. How can I do this? I know it has something to > do with the dividend....but I can't for the life of me remember. thanks! This works :-) with Ada.Text_IO; use Ada.Text_IO; procedure Demo is procedure Calculate (Value, Devisor : Integer; Result, Remainder : out Integer) is begin Remainder := Value rem Devisor; Result := (Value - Remainder) / Devisor; end Calculate; Result, Remainder : Integer; begin Calculate(26, 3, Result, Remainder); Put_Line (Integer'Image (Result) & " " & Integer'Image(Remainder)); end Demo;