Rounding a floating point number

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jacob navia

    Rounding a floating point number

    Hi

    "How can I round a number to x decimal places" ?

    This question keeps appearing. I would propose the following
    solution

    #include <float.h>
    #include <math.h>

    double roundto(double x, int digits)
    {
    int sgn=1;

    if (x == 0)
    return 0;
    if (digits DBL_DIG)
    digits = DBL_DIG;
    else if (digits < 1)
    digits = 1;

    if(x < 0.0) {
    sgn = -sgn;
    x = -x;
    }
    double p = floorl(log10l(x ));
    p--;
    p = digits-p;
    double pow10 = pow(10.0, p);
    return sgn*floor(x*pow 10+0.5)/pow10;
    }

    long double roundtol(long double x, int digits)
    {
    int sgn=1;

    if (x == 0)
    return 0;
    if (digits LDBL_DIG)
    digits = LDBL_DIG;
    else if (digits < 1)
    digits = 1;

    if(x < 0.0) {
    sgn = -sgn;
    x = -x;
    }
    long double p = floorl(log10l(x ));
    p--;
    p = digits-p;
    long double pow10 = powl(10.0, p);
    return sgn*floorl(x*po w10+0.5)/pow10;
    }
    #include <stdio.h>
    int main(void)
    {
    double d = 1.7888889988996 678;
    long double ld = 1.7888889988996 678998877L;

    for (int i = 0; i<=DBL_DIG;i++ ) {
    printf("i=%d: %.15g\n",i,roun dto(d,i));
    }
    printf("\n 1.7888889988996 678\n");
    for (int i = 0; i<=LDBL_DIG;i++ ) {
    printf("i=%d: %.18Lg\n",i,rou ndtol(ld,i));
    }
    printf("\n 1.7888889988996 678998877L\n");
    return 0;
    }

    --------------------------------------------------------------------
    I would propose it to add it to the FAQ.


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique

  • Richard Heathfield

    #2
    Re: Rounding a floating point number

    jacob navia said:
    Hi
    >
    "How can I round a number to x decimal places" ?
    >
    This question keeps appearing.
    <snip>
    I would propose it to add it to the FAQ.
    Good idea. You could call it Question 14.6.

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Comment

    • Bartc

      #3
      Re: Rounding a floating point number


      "Richard Heathfield" <rjh@see.sig.in validwrote in message
      news:xcednVO6mu LICl_anZ2dneKdn ZydnZ2d@bt.com. ..
      jacob navia said:
      >
      >Hi
      >>
      >"How can I round a number to x decimal places" ?
      >>
      >This question keeps appearing.
      >
      <snip>
      >
      >I would propose it to add it to the FAQ.
      >
      Good idea. You could call it Question 14.6.
      14.6 is already used by How to Round a Number [to an integer]

      --
      Bart


      Comment

      • jacob navia

        #4
        Re: Rounding a floating point number

        Richard Heathfield wrote:
        jacob navia said:
        >
        >Hi
        >>
        >"How can I round a number to x decimal places" ?
        >>
        >This question keeps appearing.
        >
        <snip>
        >
        >I would propose it to add it to the FAQ.
        >
        Good idea. You could call it Question 14.6.
        >
        Your kill file is not working apparently
        :-)

        That question addresses the rounding to nearest integer.
        This answers the question of rounding to a number of decimal places

        Not the same thing. But yes, we could add this to 14.6

        --
        jacob navia
        jacob at jacob point remcomp point fr
        logiciels/informatique

        Comment

        • MisterE

          #5
          Re: Rounding a floating point number

          14.6 is already used by How to Round a Number [to an integer]
          Then what need is there for this question? Its already answered in the faq.
          Multiply, round then divide.


          Comment

          • Richard Heathfield

            #6
            Re: Rounding a floating point number

            Bartc said:
            >
            "Richard Heathfield" <rjh@see.sig.in validwrote in message
            news:xcednVO6mu LICl_anZ2dneKdn ZydnZ2d@bt.com. ..
            >jacob navia said:
            >>
            >>Hi
            >>>
            >>"How can I round a number to x decimal places" ?
            >>>
            >>This question keeps appearing.
            >>
            ><snip>
            >>
            >>I would propose it to add it to the FAQ.
            >>
            >Good idea. You could call it Question 14.6.
            >
            14.6 is already used by How to Round a Number [to an integer]
            From the FAQ, Q14.6: "You can round to a certain precision by scaling:

            (int)(x / precision + 0.5) * precision"

            (int)(3.141 / 0.01 + 0.5) * 0.01 gives us:

            (int)(314.1 + 0.5) * 0.01 which is

            (int)314.6 * 0.01 which is

            314 * 0.01 which is

            3.14

            QED

            (Of course, the usual caveats about floating point apply here.)

            --
            Richard Heathfield <http://www.cpax.org.uk >
            Email: -http://www. +rjh@
            Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
            "Usenet is a strange place" - dmr 29 July 1999

            Comment

            • Martien Verbruggen

              #7
              Re: Rounding a floating point number

              On Mon, 25 Feb 2008 12:19:35 +0100,
              jacob navia <jacob@nospam.c omwrote:
              Richard Heathfield wrote:
              >jacob navia said:
              >>
              >>Hi
              >>>
              >>"How can I round a number to x decimal places" ?
              >>>
              >>This question keeps appearing.
              >>
              ><snip>
              >>
              >>I would propose it to add it to the FAQ.
              >>
              >Good idea. You could call it Question 14.6.
              >>
              That question addresses the rounding to nearest integer.
              This answers the question of rounding to a number of decimal places
              It also answers the question of how to round to a certain number of
              digits:

              \begin{quote}
              You can round to a certain precision by scaling:
              \end{quote}

              Martien
              --
              |
              Martien Verbruggen | prepBut nI vrbLike adjHungarian! qWhat's
              | artThe adjBig nProblem? -- Alec Flett
              |

              Comment

              • Bartc

                #8
                Re: Rounding a floating point number


                "Richard Heathfield" <rjh@see.sig.in validwrote in message
                news:oZGdneAOqM SCOl_aRVnyhAA@b t.com...
                Bartc said:
                >
                >>
                >"Richard Heathfield" <rjh@see.sig.in validwrote in message
                >news:xcednVO6m uLICl_anZ2dneKd nZydnZ2d@bt.com ...
                >>jacob navia said:
                >>>
                >>>Hi
                >>>>
                >>>"How can I round a number to x decimal places" ?
                >>>>
                >>>This question keeps appearing.
                >>>
                >><snip>
                >>>
                >>>I would propose it to add it to the FAQ.
                >>>
                >>Good idea. You could call it Question 14.6.
                >>
                >14.6 is already used by How to Round a Number [to an integer]
                >
                From the FAQ, Q14.6: "You can round to a certain precision by scaling:
                >
                (int)(x / precision + 0.5) * precision"
                >
                (int)(3.141 / 0.01 + 0.5) * 0.01 gives us:
                >
                (int)(314.1 + 0.5) * 0.01 which is
                >
                (int)314.6 * 0.01 which is
                >
                314 * 0.01 which is
                >
                3.14
                Yeah, you're right. Perhaps 14.6 should be written more clearly, with regard
                to what exactly it means by Precision. And an example added, like yours.
                >(int)(3.141 / 0.01 + 0.5) * 0.01
                Somehow I would be happier if that was written as:
                >(int)(3.141 *100 + 0.5) /100
                Then any errors due to 0.01 not being exactly 1/100 are someone else's
                fault.

                --
                Bart



                Comment

                • Mark McIntyre

                  #9
                  Re: Rounding a floating point number

                  MisterE wrote:
                  >14.6 is already used by How to Round a Number [to an integer]
                  >
                  Then what need is there for this question?
                  <Fx: swoosh sound of clue going over head>

                  --
                  Mark McIntyre

                  CLC FAQ <http://c-faq.com/>
                  CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

                  Comment

                  • user923005

                    #10
                    Re: Rounding a floating point number

                    On Feb 25, 2:18 am, jacob navia <ja...@nospam.c omwrote:
                    Hi
                    >
                    "How can I round a number to x decimal places" ?
                    >
                    This question keeps appearing. I would propose the following
                    solution
                    >
                    #include <float.h>
                    #include <math.h>
                    >
                    double roundto(double x, int digits)
                    {
                            int sgn=1;
                    >
                            if (x == 0)
                                    return 0;
                            if (digits DBL_DIG)
                                    digits = DBL_DIG;
                            else if (digits < 1)
                                    digits = 1;
                    >
                            if(x < 0.0) {
                                    sgn = -sgn;
                                    x = -x;
                            }
                            double p = floorl(log10l(x ));
                            p--;
                            p = digits-p;
                            double pow10 = pow(10.0, p);
                            return sgn*floor(x*pow 10+0.5)/pow10;
                    >
                    }
                    >
                    long double roundtol(long double x, int digits)
                    {
                            int sgn=1;
                    >
                            if (x == 0)
                                    return 0;
                            if (digits LDBL_DIG)
                                    digits = LDBL_DIG;
                            else if (digits < 1)
                                    digits = 1;
                    >
                            if(x < 0.0) {
                                    sgn = -sgn;
                                    x = -x;
                            }
                            long double p = floorl(log10l(x ));
                            p--;
                            p = digits-p;
                            long double pow10 = powl(10.0, p);
                            return sgn*floorl(x*po w10+0.5)/pow10;}
                    >
                    #include <stdio.h>
                    int main(void)
                    {
                            double d = 1.7888889988996 678;
                            long double ld = 1.7888889988996 678998877L;
                    >
                            for (int i = 0; i<=DBL_DIG;i++ ) {
                                    printf("i=%d: %.15g\n",i,roun dto(d,i));
                            }
                            printf("\n      1.7888889988996 678\n");
                            for (int i = 0; i<=LDBL_DIG;i++ ) {
                                    printf("i=%d: %.18Lg\n",i,rou ndtol(ld,i));
                            }
                            printf("\n      1.7888889988996 678998877L\n");
                            return 0;
                    >
                    }
                    >
                    --------------------------------------------------------------------
                    I would propose it to add it to the FAQ.
                    This is the snippet's solution (which is very similar to yours):
                    /* round number n to d decimal points */
                    double fround(double n, unsigned d)
                    {
                    return floor(n * pow(10., d) + .5) / pow(10., d);
                    }

                    Of course, no solution is really going to be satisfying, as long as
                    the output format is floating point.
                    Another question is "What kind of rounding?" Do we want banker's
                    rounding or round to nearest or what?
                    Should we create a round function for each distinct floating point
                    type?

                    Comment

                    • user923005

                      #11
                      Re: Rounding a floating point number

                      On Feb 25, 2:18 am, jacob navia <ja...@nospam.c omwrote:
                      Hi
                      >
                      "How can I round a number to x decimal places" ?
                      >
                      This question keeps appearing. I would propose the following
                      solution
                      >
                      #include <float.h>
                      #include <math.h>
                      >
                      double roundto(double x, int digits)
                      {
                              int sgn=1;
                      >
                              if (x == 0)
                                      return 0;
                              if (digits DBL_DIG)
                                      digits = DBL_DIG;
                              else if (digits < 1)
                                      digits = 1;
                      >
                              if(x < 0.0) {
                                      sgn = -sgn;
                                      x = -x;
                              }
                              double p = floorl(log10l(x ));
                              p--;
                              p = digits-p;
                              double pow10 = pow(10.0, p);
                              return sgn*floor(x*pow 10+0.5)/pow10;
                      >
                      }
                      >
                      long double roundtol(long double x, int digits)
                      {
                              int sgn=1;
                      >
                              if (x == 0)
                                      return 0;
                              if (digits LDBL_DIG)
                                      digits = LDBL_DIG;
                              else if (digits < 1)
                                      digits = 1;
                      >
                              if(x < 0.0) {
                                      sgn = -sgn;
                                      x = -x;
                              }
                              long double p = floorl(log10l(x ));
                              p--;
                              p = digits-p;
                              long double pow10 = powl(10.0, p);
                              return sgn*floorl(x*po w10+0.5)/pow10;}
                      >
                      #include <stdio.h>
                      int main(void)
                      {
                              double d = 1.7888889988996 678;
                              long double ld = 1.7888889988996 678998877L;
                      >
                              for (int i = 0; i<=DBL_DIG;i++ ) {
                                      printf("i=%d: %.15g\n",i,roun dto(d,i));
                              }
                              printf("\n      1.7888889988996 678\n");
                              for (int i = 0; i<=LDBL_DIG;i++ ) {
                                      printf("i=%d: %.18Lg\n",i,rou ndtol(ld,i));
                              }
                              printf("\n      1.7888889988996 678998877L\n");
                              return 0;
                      >
                      }
                      >
                      --------------------------------------------------------------------
                      I would propose it to add it to the FAQ.
                      The snippets solution, tweaked a little bit:

                      #include <math.h>
                      /* round number n to d decimal points */
                      long double roundl(const long double n, const unsigned d)
                      {
                      long double p = powl(10., d);
                      return floorl(n * p + .5) / p;
                      }

                      /* round number n to d decimal points */
                      double roundd(const double n, const unsigned d)
                      {
                      return (double) roundl((long double) n, d);
                      }

                      /* round number n to d decimal points */
                      double roundf(const float n, const unsigned d)
                      {
                      return (float) roundl((long double) n, d);
                      }
                      #ifdef UNIT_TEST
                      #include <stdio.h>
                      #include <stdlib.h>
                      #include <float.h>
                      int main(void)
                      {
                      long double pi = 3.1415926535897 932384626433832 795;
                      long double npi = -pi;
                      unsigned digits;
                      for (digits = 0; digits <= LDBL_DIG; digits++) {
                      printf("Roundin g by printf gives: %20.*f\n",
                      digits, pi);
                      printf("Roundin g approximation by function gives: %20.*f\n",
                      LDBL_DIG, roundl(pi, digits));
                      printf("Roundin g approximation by function gives: %20.*f\n",
                      DBL_DIG, roundd(pi, digits));
                      printf("Roundin g approximation by function gives: %20.*f\n\n",
                      FLT_DIG, roundf(pi, digits));
                      }
                      for (digits = 0; digits <= LDBL_DIG; digits++) {
                      printf("Roundin g by printf gives: %20.*f\n",
                      digits, npi);
                      printf("Roundin g approximation by function gives: %20.*f\n",
                      LDBL_DIG, roundl(npi, digits));
                      printf("Roundin g approximation by function gives: %20.*f\n",
                      DBL_DIG, roundd(npi, digits));
                      printf("Roundin g approximation by function gives: %20.*f\n\n",
                      FLT_DIG, roundf(npi, digits));
                      }
                      return 0;
                      }
                      #endif
                      /*
                      Rounding by printf gives: 3
                      Rounding approximation by function gives: 3.0000000000000 00
                      Rounding approximation by function gives: 3.0000000000000 00
                      Rounding approximation by function gives: 3.000000

                      Rounding by printf gives: 3.1
                      Rounding approximation by function gives: 3.1000000000000 00
                      Rounding approximation by function gives: 3.1000000000000 00
                      Rounding approximation by function gives: 3.100000

                      Rounding by printf gives: 3.14
                      Rounding approximation by function gives: 3.1400000000000 00
                      Rounding approximation by function gives: 3.1400000000000 00
                      Rounding approximation by function gives: 3.140000

                      Rounding by printf gives: 3.142
                      Rounding approximation by function gives: 3.1420000000000 00
                      Rounding approximation by function gives: 3.1420000000000 00
                      Rounding approximation by function gives: 3.142000

                      Rounding by printf gives: 3.1416
                      Rounding approximation by function gives: 3.1416000000000 00
                      Rounding approximation by function gives: 3.1416000000000 00
                      Rounding approximation by function gives: 3.141600

                      Rounding by printf gives: 3.14159
                      Rounding approximation by function gives: 3.1415900000000 00
                      Rounding approximation by function gives: 3.1415900000000 00
                      Rounding approximation by function gives: 3.141590

                      Rounding by printf gives: 3.141593
                      Rounding approximation by function gives: 3.1415930000000 00
                      Rounding approximation by function gives: 3.1415930000000 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.1415927
                      Rounding approximation by function gives: 3.1415927000000 00
                      Rounding approximation by function gives: 3.1415927000000 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.14159265
                      Rounding approximation by function gives: 3.1415926500000 00
                      Rounding approximation by function gives: 3.1415926500000 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.141592654
                      Rounding approximation by function gives: 3.1415926540000 00
                      Rounding approximation by function gives: 3.1415926540000 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.1415926536
                      Rounding approximation by function gives: 3.1415926536000 00
                      Rounding approximation by function gives: 3.1415926536000 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.14159265359
                      Rounding approximation by function gives: 3.1415926535900 00
                      Rounding approximation by function gives: 3.1415926535900 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.141592653590
                      Rounding approximation by function gives: 3.1415926535900 00
                      Rounding approximation by function gives: 3.1415926535900 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.1415926535898
                      Rounding approximation by function gives: 3.1415926535898 00
                      Rounding approximation by function gives: 3.1415926535898 00
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.1415926535897 9
                      Rounding approximation by function gives: 3.1415926535897 90
                      Rounding approximation by function gives: 3.1415926535897 90
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: 3.1415926535897 93
                      Rounding approximation by function gives: 3.1415926535897 93
                      Rounding approximation by function gives: 3.1415926535897 93
                      Rounding approximation by function gives: 3.141593

                      Rounding by printf gives: -3
                      Rounding approximation by function gives: -3.0000000000000 00
                      Rounding approximation by function gives: -3.0000000000000 00
                      Rounding approximation by function gives: -3.000000

                      Rounding by printf gives: -3.1
                      Rounding approximation by function gives: -3.1000000000000 00
                      Rounding approximation by function gives: -3.1000000000000 00
                      Rounding approximation by function gives: -3.100000

                      Rounding by printf gives: -3.14
                      Rounding approximation by function gives: -3.1400000000000 00
                      Rounding approximation by function gives: -3.1400000000000 00
                      Rounding approximation by function gives: -3.140000

                      Rounding by printf gives: -3.142
                      Rounding approximation by function gives: -3.1420000000000 00
                      Rounding approximation by function gives: -3.1420000000000 00
                      Rounding approximation by function gives: -3.142000

                      Rounding by printf gives: -3.1416
                      Rounding approximation by function gives: -3.1416000000000 00
                      Rounding approximation by function gives: -3.1416000000000 00
                      Rounding approximation by function gives: -3.141600

                      Rounding by printf gives: -3.14159
                      Rounding approximation by function gives: -3.1415900000000 00
                      Rounding approximation by function gives: -3.1415900000000 00
                      Rounding approximation by function gives: -3.141590

                      Rounding by printf gives: -3.141593
                      Rounding approximation by function gives: -3.1415930000000 00
                      Rounding approximation by function gives: -3.1415930000000 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.1415927
                      Rounding approximation by function gives: -3.1415927000000 00
                      Rounding approximation by function gives: -3.1415927000000 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.14159265
                      Rounding approximation by function gives: -3.1415926500000 00
                      Rounding approximation by function gives: -3.1415926500000 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.141592654
                      Rounding approximation by function gives: -3.1415926540000 00
                      Rounding approximation by function gives: -3.1415926540000 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.1415926536
                      Rounding approximation by function gives: -3.1415926536000 00
                      Rounding approximation by function gives: -3.1415926536000 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.14159265359
                      Rounding approximation by function gives: -3.1415926535900 00
                      Rounding approximation by function gives: -3.1415926535900 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.141592653590
                      Rounding approximation by function gives: -3.1415926535900 00
                      Rounding approximation by function gives: -3.1415926535900 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.1415926535898
                      Rounding approximation by function gives: -3.1415926535898 00
                      Rounding approximation by function gives: -3.1415926535898 00
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.1415926535897 9
                      Rounding approximation by function gives: -3.1415926535897 90
                      Rounding approximation by function gives: -3.1415926535897 90
                      Rounding approximation by function gives: -3.141593

                      Rounding by printf gives: -3.1415926535897 93
                      Rounding approximation by function gives: -3.1415926535897 93
                      Rounding approximation by function gives: -3.1415926535897 93
                      Rounding approximation by function gives: -3.141593
                      */

                      Comment

                      • CBFalconer

                        #12
                        Re: Rounding a floating point number

                        jacob navia wrote:
                        >
                        "How can I round a number to x decimal places" ?
                        >
                        This question keeps appearing. I would propose the following
                        >
                        .... snip 75 or so lines ...

                        Why all this gyration? I found the following in the c standard:

                        7.12.9.6 The round functions
                        Synopsis
                        [#1]
                        #include <math.h>
                        double round(double x);
                        float roundf(float x);
                        long double roundl(long double x);

                        Description

                        [#2] The round functions round their argument to the nearest
                        integer value in floating-point format, rounding halfway
                        cases away from zero, regardless of the current rounding
                        direction.

                        Returns

                        [#3] The round functions return the rounded integer value.

                        --
                        [mail]: Chuck F (cbfalconer at maineline dot net)
                        [page]: <http://cbfalconer.home .att.net>
                        Try the download section.



                        --
                        Posted via a free Usenet account from http://www.teranews.com

                        Comment

                        • Ben Pfaff

                          #13
                          Re: Rounding a floating point number

                          CBFalconer <cbfalconer@yah oo.comwrites:
                          jacob navia wrote:
                          >>
                          >"How can I round a number to x decimal places" ?
                          >>
                          >This question keeps appearing. I would propose the following
                          >>
                          ... snip 75 or so lines ...
                          >
                          Why all this gyration? I found the following in the c standard:
                          >
                          7.12.9.6 The round functions
                          Those functions are new in C99.
                          --
                          char a[]="\n .CJacehknorstu" ;int putchar(int);in t main(void){unsi gned long b[]
                          ={0x67dffdff,0x 9aa9aa6a,0xa77f fda9,0x7da6aa6a ,0xa67f6aaa,0xa a9aa9f6,0x11f6} ,*p
                          =b,i=24;for(;p+ =!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
                          2:{i++;if(i)bre ak;else default:continu e;if(0)case 1:putchar(a[i&15]);break;}}}

                          Comment

                          • user923005

                            #14
                            Re: Rounding a floating point number

                            On Feb 25, 4:29 pm, Ben Pfaff <b...@cs.stanfo rd.eduwrote:
                            CBFalconer <cbfalco...@yah oo.comwrites:
                            jacob navia wrote:
                            >
                            "How can I round a number to x decimal places" ?
                            >
                            This question keeps appearing. I would propose the following
                            >
                            ... snip 75 or so lines ...
                            >
                            Why all this gyration?  I found the following in the c standard:
                            >
                              7.12.9.6  The round functions
                            >
                            Those functions are new in C99.
                            And they don't round to x decimal places, unless x happens to be
                            zero. (Admittedly, you could manually scale it.)

                            Comment

                            • Keith Thompson

                              #15
                              Re: Rounding a floating point number

                              Ben Pfaff <blp@cs.stanfor d.eduwrites:
                              CBFalconer <cbfalconer@yah oo.comwrites:
                              >jacob navia wrote:
                              >>"How can I round a number to x decimal places" ?
                              >>>
                              >>This question keeps appearing. I would propose the following
                              >>>
                              >... snip 75 or so lines ...
                              >>
                              >Why all this gyration? I found the following in the c standard:
                              >>
                              > 7.12.9.6 The round functions
                              >
                              Those functions are new in C99.
                              So are floorl and log10l, which jacob's code uses; it also mixes
                              declarations and statements within a block. An implementation that
                              can handle jacob's code should provide the round functions.

                              --
                              Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
                              Nokia
                              "We must do something. This is something. Therefore, we must do this."
                              -- Antony Jay and Jonathan Lynn, "Yes Minister"

                              Comment

                              Working...