🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18243

Re: trouble with round

#18243
From: Dave Frizzell
Date: Tue, 21 Jul 1998 00:00
38 lines
2128 bytes
rich,

i appreciate for the help.  the code worked perfectly.  oh btw, thanks
also for the math (divide - vs - multiply) lesson. :~)  point well
taken. 

davef

Rich Downing wrote:
> First of all, might I suggest that you always perform your
> multiplications before performing division.
> 
> totalGradePoints/max_points will probably result in some roundoff or
> precision error, which error will then be multiplied by
> MAX_PERCENTAGE. This type of error becomes minimized if your change
> your statement to  (totalGradePoints*MAX_PERCENTAGE) / max_points
> 
> To round to the second decimal you can use:
> 
> double examPercent = (double)(Math.round(
> totalGradePoints*MAX_PERCENTAGE * 100 / max_points))  / 100;
> 
> Note that the following applies to normal "business rules" rounding.
> In mathematics, rounding is done a bit differently.  Since the number
> 0 is not rounded; numbers 1,2,3,4,5 are rounded up, and numbers
> 6,7,8,9 are rounded down.  Hence one is rounding up 5 times and down 4
> times.
> 
> To correct this one rounds up or down depending upon whether the
> preceding digit was even or odd. (assuming random data).
> 
> Rich
> ----------------------------------------------------------------------
> Richard V. Downing              Work email: richard.downing@vsin.com
> Senior Software Engineer        Home email: rvd@mindspring.com
> VideoConferencing Systems, Inc. Web: http://rvd.home.mindspring.com
> Norcross, Ga
> ------------ When surrounded by wolves 'tis best to howl -------------
Technical Details
Message-ID: <35B4ABD1.562F@jtechmed.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35B2DFEC.1F19@jtechmed.com> <35b35396.13036243@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f5c385332d5757e
X-Google-Attributes: gidf74b3,public
From: Dave Frizzell <davef@jtechmed.com>
Subject: Re: trouble with round
Date: 1998/07/21
Message-ID: <35B4ABD1.562F@jtechmed.com>
X-Deja-AN: 373513623
Content-Transfer-Encoding: 7bit
References: <35B2DFEC.1F19@jtechmed.com> <35b35396.13036243@forums.borland.com>
To: Rich Downing <rvd@mindspring.com>
Content-Type: text/plain; charset=us-ascii
Organization: JTech Medical
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language