Re: javascript - rounding to whole integer

by 2Nerotik <2nerotik(at)nisa.net>

 Date:  Sat, 22 Jan 2000 10:59:00 -0800
 To:  hwg-techniques(at)hwg.org
 In-Reply-To:  ia
  todo: View Thread, Original
I think there is a round command for JavaScript, unfortunately I'm moving 
at the end
of this month and have already packed up my JavaScript book but have taken 
a look
at the Netscape center for the info.
http://developer.netscape.com/docs/manuals/js/client/jsref/index.htm

This is what it says:

Syntax
round(x)

Parameters
A number

Description
If the fractional portion of number is .5 or greater, the argument is 
rounded to the next higher integer. If the fractional portion of number is 
less than .5, the argument is rounded to the next lower integer.

Because round is a static method of Math, you always use it as 
Math.round(), rather than as a method of a Math object you created.

Examples
//Returns the value 20
x=Math.round(20.49)

//Returns the value 21
x=Math.round(20.5)

//Returns the value -20
x=Math.round(-20.5)

//Returns the value -21
x=Math.round(-20.51)


At 08:53 AM 22/01/2000 -0600, Alan Greiner wrote:
>I am working on a javascript that needs to display a percent but I want to 
>get rid of the decimal places in the percent and have it round either up 
>or down in the correct fashion.  Is there an function that will do this.
>
>Example:                33.333333333%   should be 33%
>                         33.5669%                should be 34%
>TIA,
>Alan Greiner                                    greiner(at)gowrie.k12.ia.us
>515-352-3351 - office
>515-386-3774 - home

.oOo.
|| Everyone has a photographic memory. Some don't have film.
||
||  Addicted 2 Swing ---> http://www.nisa.net/~2nerotik/
||  Fontaholic ? ---> http://www.fontsanon.com
||  HTML Writers Guild ---> http://www.hwg.org

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA