round a number up

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trevor Stapleton

    #1

    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

  • Vincent van Beveren

    #2
    Re: round a number up

    devedge and msdn both good references. 3 clicks and you have your
    answer.


    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:
    [color=blue]
    > 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
    >[/color]

    Comment

    • alu

      #3
      Re: round a number up

      "Trevor Stapleton" <tws4711@ntlwor ld.com> wrote in message
      news:40cdb6af.9 029234@news.ntl world.com...[color=blue]
      > 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[/color]

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

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


      Comment

      • Trevor Stapleton

        #4
        Re: round a number up

        On Mon, 14 Jun 2004 16:47:01 +0200, Vincent van Beveren
        <vincent@provid ent.remove.this .nl> wrote:[color=blue]
        >
        >but the thing you are looking for is Math.ceil(2.5);
        >[/color]
        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

        Comment

        • Trevor Stapleton

          #5
          Re: round a number up

          On Mon, 14 Jun 2004 10:41:50 -0400, "alu" <none@none.co m> wrote:[color=blue]
          >
          >// Returns the value 3
          >x = Math.round(2.5)
          >[/color]
          Thanks for the info, I now have that little problem sorted
          Trevor

          Comment

          • Grant Wagner

            #6
            Re: round a number up

            Trevor Stapleton wrote:
            [color=blue]
            > On Mon, 14 Jun 2004 16:47:01 +0200, Vincent van Beveren
            > <vincent@provid ent.remove.this .nl> wrote:[color=green]
            > >
            > >but the thing you are looking for is Math.ceil(2.5);
            > >[/color]
            > 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[/color]

            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 <gwagner@agrico reunited.com>

            * Client-side Javascript and Netscape 4 DOM Reference available
            at:
            *


            * 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


            Comment

            • Dr John Stockton

              #7
              Re: round a number up

              JRS: In article <40cdd1d2.76203 1@news.ntlworld .com>, seen in
              news:comp.lang. javascript, Trevor Stapleton <tws4711@ntlwor ld.com>
              posted at Mon, 14 Jun 2004 16:28:41 :[color=blue]
              >On Mon, 14 Jun 2004 16:47:01 +0200, Vincent van Beveren
              ><vincent@provi dent.remove.thi s.nl> wrote:[color=green]
              >>
              >>but the thing you are looking for is Math.ceil(2.5);
              >>[/color]
              >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?[/color]

              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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

              Comment

              Working...