473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

round a number up

in a function i am working on i can end up with a variable named
dwncount holding the value 2.5 or some other fraction,
I know this can be rounded up, but how? or what is the syntax?
TIA
Trevor

Jul 23 '05 #1
6 1405
devedge and msdn both good references. 3 clicks and you have your
answer.

http://devedge.netscape.com/central/javascript/
http://msdn.microsoft.com/library/en...oriJScript.asp

but the thing you are looking for is Math.ceil(2.5);

good luck,
Vincent
Trevor Stapleton wrote:
in a function i am working on i can end up with a variable named
dwncount holding the value 2.5 or some other fraction,
I know this can be rounded up, but how? or what is the syntax?
TIA
Trevor


Jul 23 '05 #2
alu
"Trevor Stapleton" <tw*****@ntlworld.com> wrote in message
news:40**************@news.ntlworld.com...
in a function i am working on i can end up with a variable named
dwncount holding the value 2.5 or some other fraction,
I know this can be rounded up, but how? or what is the syntax?
TIA
Trevor


--------------------------

// Returns the value 3
x = Math.round(2.5)
Jul 23 '05 #3
On Mon, 14 Jun 2004 16:47:01 +0200, Vincent van Beveren
<vi*****@provident.remove.this.nl> wrote:

but the thing you are looking for is Math.ceil(2.5);

Thanks for the info Vincent, may I ask do you know of
an alternative to using document.write and so avoid
opening a new page when the function containing
it is called?
TIA
Trevor
Jul 23 '05 #4
On Mon, 14 Jun 2004 10:41:50 -0400, "alu" <no**@none.com> wrote:

// Returns the value 3
x = Math.round(2.5)

Thanks for the info, I now have that little problem sorted
Trevor
Jul 23 '05 #5
Trevor Stapleton wrote:
On Mon, 14 Jun 2004 16:47:01 +0200, Vincent van Beveren
<vi*****@provident.remove.this.nl> wrote:

but the thing you are looking for is Math.ceil(2.5);

Thanks for the info Vincent, may I ask do you know of
an alternative to using document.write and so avoid
opening a new page when the function containing
it is called?
TIA
Trevor


document.write() does not open a new page, it re-writes the
current page, wiping out any existing HTML, including any script
you might have on that page.

To update the page dynamically see the FAQ: <url:
http://jibbering.com/faq/#FAQ4_15 />

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available
at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #6
JRS: In article <40*************@news.ntlworld.com>, seen in
news:comp.lang.javascript, Trevor Stapleton <tw*****@ntlworld.com>
posted at Mon, 14 Jun 2004 16:28:41 :
On Mon, 14 Jun 2004 16:47:01 +0200, Vincent van Beveren
<vi*****@provident.remove.this.nl> wrote:

but the thing you are looking for is Math.ceil(2.5);

Thanks for the info Vincent, may I ask do you know of
an alternative to using document.write and so avoid
opening a new page when the function containing
it is called?


Try reading the FAQ.

As regards your rounding, it depends on what you mean by "up".
Math.ceil(X) will round X towards plus infinity; if you want to round X
away from zero then maybe X<0 ? -Math.ceil(-X) : Math.ceil(X)

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Schklerg | last post by:
I have this script performing a calculation on a page on my site: <script language="JavaScript"> function compute_weight(form) { var weight = form.wt.value; var pgs = form.pgs.value; var ppi =...
6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
10
by: tmeister | last post by:
I'm trying to determine the best approach for rounding in an application I'm building. Unfortunately it appears as though SQL Server and VB.NET round in different ways. SQL Server select...
9
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something...
4
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal =...
36
by: Phat G5 (G3) | last post by:
Has anyone found a reliable way to force JS to round to a specific number of places? Every time I try I get different results. For example, I'd need to round 3.4589 to 2 places. What is the most...
4
by: Fuzzydave | last post by:
I have been using a round command in a few places to round a value to zero decimal places using the following format, round('+value+', 0) but this consistantly returns the rounded result of...
6
by: dkirkdrei | last post by:
I am looking for a way to round a number (which will be displayed as a dollar amount) to the nearest nickel. Using the php round function only allows you to control the number of decimal places in...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
0
by: Edwin.Madari | last post by:
>>round(76.1, -2) 100.0 80.0 76.0 builtin function round, will work for you...... Help on built-in function round in module __builtin__: round(...) round(number) -floating point number
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.