rounding off numbers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr John Stockton

    #16
    Re: rounding off numbers

    JRS: In article <brfn22$oqs$1@s parta.btinterne t.com>, seen in
    news:comp.lang. javascript, bagbourne <noway@noway.co m> posted at Sat, 13
    Dec 2003 18:50:43 :-
    [color=blue][color=green]
    >> In article <LxGCb.99$sW5.5 0@newsread2.new s.atl.earthlink .net>, Allen
    >> Thompson <genericjoe@min dspring.com> wrote:
    >>
    >>[color=darkred]
    >>>Is there a script that will round off a number to a certain number of
    >>>decimal places? -Allen Thompson[/color][/color][/color]
    [color=blue]
    >or use the toFixed() method of the Number object:
    >
    >http://devedge.netscape.com/library/...ference/number
    >.html#119313 7[/color]

    Method toFixed() should not be used on the Internet. Implementations
    are buggy, and the method is not available on all browsers currently in
    use.

    It is wise to understand the newsgroup FAQ before answering here.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.

    Comment

    • Dr John Stockton

      #17
      Re: rounding off numbers

      JRS: In article <13122003163430 1133%denmarks@d csi.net>, seen in
      news:comp.lang. javascript, Dennis M. Marks <denmarks@dcsi. net> posted at
      Sat, 13 Dec 2003 16:34:30 :-[color=blue]
      >The original question was:
      >Is there a script that will round off a number to a certain number of
      >decimal places? -Allen Thompson
      >
      >It did not state "display" a certain number of decimal places. My
      >answer is mathematically correct. To show trailing zeros after the
      >decimal point text zeros would have to be affixed to the end. It's too
      >bad that javascript doesn't have output formatting like some other
      >languages.[/color]

      Objects of type Number do not have decimal places. They are binary,
      with 52 binary places after an implicit "1.", and an exponent.
      Therefore, your code does not do the impossible function that is asked
      for.

      Agreed that javascript should have had proper number-to-string
      formatting built in; however, please post here if there is any
      reasonable formatting required that cannot be found by using the
      newsgroup FAQ.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.

      Comment

      • Thomas 'PointedEars' Lahn

        #18
        Re: rounding off numbers

        @SM wrote:
        [color=blue]
        > bagbourne a ecrit :[color=green]
        >> http://devedge.netscape.com/library/...r.html#1193137[/color]
        >
        > very interesting
        > they send me to a page to tell me to download NN7
        > beuark ! :-((([/color]

        They do not. Tested with Mozilla/4.0 (compatible; MSIE 6.0;
        Windows NT 5.0; Q312461).

        Besides, JavaScript 1.5 in implemented in Mozilla/5.0 which
        only *includes* Netscape 6+.
        [color=blue]
        > --[/color]

        <prayer_wheel > The trailing space is missing. </prayer_wheel>


        PointedEars

        Comment

        • Dr John Stockton

          #19
          Re: rounding off numbers

          JRS: In article <Y4-dnUHr0aPtTUaiRV n-jg@comcast.com> , seen in
          news:comp.lang. javascript, Mike <mike{removeToe mail}@synovic.c om> posted
          at Sat, 13 Dec 2003 20:52:30 :-[color=blue]
          >Here is an actual code example of the formula defined by Dennis Marks.
          >
          >function number_ClipToTh eHundredth(valu e) {
          > return Math.round(pars eFloat(value) * 100)/100;
          >}
          >
          >Change the 100 to any decimal place you want, 10, 100, 1000 (10^x).[/color]

          For what purpose do you call parseFloat? The OP wishes to start with a
          number.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.

          Comment

          • Dr John Stockton

            #20
            Re: rounding off numbers

            JRS: In article <Xns9451571F1CA 0ebohlmanomsdev com@130.133.1.4 >, seen in
            news:comp.lang. javascript, Eric Bohlman <ebohlman@earth link.net> posted
            at Sun, 14 Dec 2003 06:20:05 :-[color=blue]
            >"Fabian" <lajzar@hotmail .com> wrote in news:brgqee$33v jm$2@ID-
            >174912.news.un i-berlin.de:
            >[color=green]
            >> To avoid floating errors, it is wise to leave the final divisor off
            >> until you are ready to display the number. Wherver possible, it is best
            >> to use whole numbers in javascript.[/color]
            >
            >Or any language in which arithmetic is done in floating point. For
            >example, when doing financial calculations, the rule is always to convert
            >all the numbers you use into the smallest units you do business with (for
            >ordinary commerce, that would be cents or your country's equivalent) and
            >only convert to larger units (e.g. dollars) at the very end.[/color]

            No, that is not always the rule. The rule used (after the fixing of
            parities) for converting the currencies which are now replaced by the
            Euro, to the Euro and among each other, was rigorously specified, and
            was different. ISTM likely that a similar rule will be used when other
            countries join.

            [color=blue]
            >There's an entire branch of mathematics (numerical analysis) devoted to the
            >study of the consequences of dealing with concrete representations of
            >numbers rather than ideal abstract numbers. When you study numerical
            >analysis you learn, for example, that if you try to subtract one large
            >floating-point number from another larger floating-point number that's
            >nearly equal to it,[/color]

            I hope that most would have learned the results of such subtraction long
            before studying numerical analysis.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk / ??.Stockton@phy sics.org ©
            Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
            Correct <= 4-line sig. separator as above, a line precisely "-- " (SoRFC1036)
            Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)

            Comment

            • @SM

              #21
              Re: rounding off numbers

              Thomas 'PointedEars' Lahn a ecrit :
              [color=blue]
              > @SM wrote:
              >[color=green]
              > > bagbourne a ecrit :[color=darkred]
              > >> http://devedge.netscape.com/library/...r.html#1193137[/color]
              > >
              > > very interesting
              > > they send me to a page to tell me to download NN7
              > > beuark ! :-((([/color]
              >
              > They do not.[/color]

              They Did !
              tested with NC 4.5 (French on Mac PPC system 8.6)

              [color=blue]
              > Tested with Mozilla/4.0 (compatible; MSIE 6.0;
              > Windows NT 5.0; Q312461).[/color]

              --
              *************** *************** *************** *************** **
              Stéphane MORIAUX : mailto:stephane OTER-MOImoriaux@wana doo.fr

              Comment

              • Thomas 'PointedEars' Lahn

                #22
                Re: rounding off numbers

                @SM wrote:
                [color=blue]
                > Thomas 'PointedEars' Lahn a ecrit :[color=green]
                >> @SM wrote:[color=darkred]
                >> > bagbourne a ecrit :
                >> >> http://devedge.netscape.com/library/...r.html#1193137
                >> >
                >> > very interesting
                >> > they send me to a page to tell me to download NN7
                >> > beuark ! :-((([/color]
                >>
                >> They do not.[/color]
                >
                > They Did !
                > tested with NC 4.5 (French on Mac PPC system 8.6)[/color]

                And with Mozilla/4.8 [en] (Windows NT 5.0; U) and below.

                Well, just click the Back button or the "Continue using DevEdge with
                this browser" link and the info document will not appear again. They
                are right to drop you a note that you are using a buggy and outdated
                browser.
                [color=blue]
                > --[/color]
                .....^
                When will you ever learn? :-(


                PointedEars

                Comment

                • @SM

                  #23
                  Re: rounding off numbers



                  Thomas 'PointedEars' Lahn a ecrit :[color=blue]
                  >
                  > @SM wrote:
                  >[color=green]
                  > > Thomas 'PointedEars' Lahn a ecrit :[color=darkred]
                  > >> @SM wrote:
                  > >> > bagbourne a ecrit :
                  > >> >> http://devedge.netscape.com/library/...r.html#1193137
                  > >> >
                  > >> > very interesting
                  > >> > they send me to a page to tell me to download NN7[/color][/color][/color]
                  [color=blue]
                  >
                  > Well, just click the Back button or the "Continue using DevEdge with
                  > this browser" link and the info document will not appear again. They
                  > are right to drop you a note that you are using a buggy and outdated
                  > browser.[/color]

                  Fastidious !
                  Because I dont know my browser is old ?

                  What they do for I can use a "new" browser ? :-(((((
                  Because Mozilla 5 is unuseful on my machine.

                  [color=blue][color=green]
                  > > --[/color]
                  > ....^
                  > When will you ever learn? :-(
                  >
                  > PointedEars[/color]

                  Beter isn't without signature ;-))
                  (for reply url, I'm working about it, let me some time)

                  Comment

                  Working...