Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Rounding

Rounding

Scheduled Pinned Locked Moved The Lounge
questionlounge
30 Posts 13 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P PaulowniaK

    My understanding of rounding to N significant figure is like this:

    1234 to 3 significant figures = 1230
    1235 to 3 significant figures = 1240
    1236 to 3 significant figures = 1240

    The trouble is, I need

    1234 to 3 significant figures = 1230
    1235 to 3 significant figures = 1230
    1236 to 3 significant figures = 1240

    The point is, rather than rounding up or down depending on whether the N+1th digit is 4 or 5, but whether it is 5 or 6.

    Almost, but not quite, entirely unlike... me...

    D Offline
    D Offline
    DaveAuld
    wrote on last edited by
    #19

    Round half down + Significant.

    Dave Find Me On:Web|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject

    P 1 Reply Last reply
    0
    • P PaulowniaK

      My understanding of rounding to N significant figure is like this:

      1234 to 3 significant figures = 1230
      1235 to 3 significant figures = 1240
      1236 to 3 significant figures = 1240

      The trouble is, I need

      1234 to 3 significant figures = 1230
      1235 to 3 significant figures = 1230
      1236 to 3 significant figures = 1240

      The point is, rather than rounding up or down depending on whether the N+1th digit is 4 or 5, but whether it is 5 or 6.

      Almost, but not quite, entirely unlike... me...

      A Offline
      A Offline
      Agent__007
      wrote on last edited by
      #20

      How about "N Significant Half-Down Rounding[^]"?

      Whether I think I can, or think I can't, I am always bloody right!

      1 Reply Last reply
      0
      • P PaulowniaK

        My understanding of rounding to N significant figure is like this:

        1234 to 3 significant figures = 1230
        1235 to 3 significant figures = 1240
        1236 to 3 significant figures = 1240

        The trouble is, I need

        1234 to 3 significant figures = 1230
        1235 to 3 significant figures = 1230
        1236 to 3 significant figures = 1240

        The point is, rather than rounding up or down depending on whether the N+1th digit is 4 or 5, but whether it is 5 or 6.

        Almost, but not quite, entirely unlike... me...

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #21

        So depending on how you want to treat negative numbers you want either "Significant digits round half down" or "Significant digits round half towards zero".

        Wrong is evil and must be defeated. - Jeff Ello[^]

        P 1 Reply Last reply
        0
        • P PaulowniaK

          OK, bad example...

          123 would be 120.
          125 would be 120.
          126 would be 130.

          etc. etc.

          The point not being the number of significant digits you end up with, but the fact that the rounding is happening at 5 and 6 rather than the more usual 4 and 5.

          Almost, but not quite, entirely unlike... me...

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #22

          See my other answer, or Daves.

          Wrong is evil and must be defeated. - Jeff Ello[^]

          1 Reply Last reply
          0
          • D DaveAuld

            Round half down + Significant.

            Dave Find Me On:Web|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject

            P Offline
            P Offline
            PaulowniaK
            wrote on last edited by
            #23

            Cheers. I think "round half down" is the term I needed. :thumbsup:

            Almost, but not quite, entirely unlike... me...

            1 Reply Last reply
            0
            • J Jorgen Andersson

              So depending on how you want to treat negative numbers you want either "Significant digits round half down" or "Significant digits round half towards zero".

              Wrong is evil and must be defeated. - Jeff Ello[^]

              P Offline
              P Offline
              PaulowniaK
              wrote on last edited by
              #24

              All values are positive, due to the nature of the application. "Round half down" was the term I was looking for. Thanks for your help. :cool:

              Almost, but not quite, entirely unlike... me...

              1 Reply Last reply
              0
              • L Lost User

                http://en.wikipedia.org/wiki/Rounding[^] "Round half down to nearest integral multiplier power of 10"

                Peter Wasser "The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell

                P Offline
                P Offline
                PaulowniaK
                wrote on last edited by
                #25

                Thanks, "Round half down" was the term I was looking for. :)

                Almost, but not quite, entirely unlike... me...

                1 Reply Last reply
                0
                • S Steve Wellens

                  How's this: Round to one significant digit.

                  D Offline
                  D Offline
                  Duncan Edwards Jones
                  wrote on last edited by
                  #26

                  ...or rounding to the most significant digit. (I'd suggest that we call this "politicians rounding")

                  1 Reply Last reply
                  0
                  • J JMK NI

                    This is standard rounding The irony is that people are so used to bankers rounding they get confused when they see ordinary rounding, but this is the kind you probably learned about in school! Disregard, I'm an idiot

                    B Offline
                    B Offline
                    BillWoodruff
                    wrote on last edited by
                    #27

                    JMK-NI wrote:

                    Disregard, I'm an idiot

                    Well, JMK-NI, don't worry too much: you are in the place for idiocy. It's kind of like a "contagious skin rash," here, on the Lounge, it breaks out in different people, and makes different people scratch in different places, while others scratch their heads. cheers, Bill

                    “I have diligently numbered the days of pure and genuine happiness which have fallen to my lot: They amount to 14.” Abd-Ar Rahman III, Caliph of Cordoba, circa 950CE.

                    1 Reply Last reply
                    0
                    • P PaulowniaK

                      A very random question, but CPians' answers may possibly be useful for me... Is there a word or a phrase describing this:

                      1.5 gets rounded to 1.
                      1.6 gets rounded to 2.

                      150 gets rounded to 100.
                      160 gets rounded to 200.

                      and any other similar effects...

                      :confused: Any suggestions greatly appreciated.

                      Almost, but not quite, entirely unlike... me...

                      M Offline
                      M Offline
                      Michael Pauli
                      wrote on last edited by
                      #28

                      The 1.5 -> 1 is a little strange. Except for that you can use

                      double MagicFormula(double x)
                      {
                      var d = Math.Log10(x);
                      var f = Math.Pow(10.0, d);
                      var res = Math.Round(x / f, 0) * f;
                      var res2 = Math.Round(res, 0);
                      return res2;
                      }

                      Michael Pauli

                      1 Reply Last reply
                      0
                      • P PaulowniaK

                        OK, bad example...

                        123 would be 120.
                        125 would be 120.
                        126 would be 130.

                        etc. etc.

                        The point not being the number of significant digits you end up with, but the fact that the rounding is happening at 5 and 6 rather than the more usual 4 and 5.

                        Almost, but not quite, entirely unlike... me...

                        G Offline
                        G Offline
                        Gary Wheeler
                        wrote on last edited by
                        #29

                        I think the word you are looking for is 'wrong'.

                        Software Zen: delete this;

                        1 Reply Last reply
                        0
                        • P PaulowniaK

                          A very random question, but CPians' answers may possibly be useful for me... Is there a word or a phrase describing this:

                          1.5 gets rounded to 1.
                          1.6 gets rounded to 2.

                          150 gets rounded to 100.
                          160 gets rounded to 200.

                          and any other similar effects...

                          :confused: Any suggestions greatly appreciated.

                          Almost, but not quite, entirely unlike... me...

                          N Offline
                          N Offline
                          newton saber
                          wrote on last edited by
                          #30

                          Kind of like ceiling / floor, but that's for decimal. http://en.wikipedia.org/wiki/Floor_and_ceiling_functions[^]

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups