How to find the next set of ten of a number?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Scheer

    How to find the next set of ten of a number?

    Hi.

    Suppose I have a number 55. The next exact set of ten will be 60. If
    my number is 72 the next exact set of then will be 80 and so on. Is
    there any function that can find the next set of ten of a given
    number? I read abou the Math class, but it seems that it doesn't have
    such a function.

    Regards,
    Robert Scheer
  • Steve Gerrard

    #2
    Re: How to find the next set of ten of a number?

    Robert Scheer wrote:
    Hi.
    >
    Suppose I have a number 55. The next exact set of ten will be 60. If
    my number is 72 the next exact set of then will be 80 and so on. Is
    there any function that can find the next set of ten of a given
    number? I read abou the Math class, but it seems that it doesn't have
    such a function.
    >
    Regards,
    Robert Scheer
    How about
    y = Math.Ceiling(x / 10) * 10


    Comment

    • Lloyd Sheen

      #3
      Re: How to find the next set of ten of a number?

      Robert Scheer wrote:
      Hi.
      >
      Suppose I have a number 55. The next exact set of ten will be 60. If
      my number is 72 the next exact set of then will be 80 and so on. Is
      there any function that can find the next set of ten of a given
      number? I read abou the Math class, but it seems that it doesn't have
      such a function.
      >
      Regards,
      Robert Scheer
      There is no function to do that but this will work:

      Dim number as integer = 55
      dim result as integer = ((number+10)\10 )*10

      Hope this helps
      LS

      Comment

      • rowe_newsgroups

        #4
        Re: How to find the next set of ten of a number?

        On Jul 26, 2:04 pm, Lloyd Sheen <a...@b.cwrot e:
        Robert Scheer wrote:
        Hi.
        >
        Suppose I have a number 55. The next exact set of ten will be 60. If
        my number is 72 the next exact set of then will be 80 and so on. Is
        there any function that can find the next set of ten of a given
        number? I read abou the Math class, but it seems that it doesn't have
        such a function.
        >
        Regards,
        Robert Scheer
        >
        There is no function to do that but this will work:
        >
        Dim number as integer = 55
        dim result as integer = ((number+10)\10 )*10
        >
        Hope this helps
        LS
        That will definitely work, but I can't say I've ever like how "\"
        division does the casting to the integer. I've found that many
        programmers (especially junior level) don't know about that feature
        and it can lead to some very confused maintenance programmers. For
        that reason I highly recommend that whenever you use that feature, you
        put in a comment to make sure future developers know what's going on.

        Thanks,

        Seth Rowe [MVP]

        Comment

        • Steve Gerrard

          #5
          Re: How to find the next set of ten of a number?

          rowe_newsgroups wrote:
          >There is no function to do that but this will work:
          >>
          >Dim number as integer = 55
          >dim result as integer = ((number+10)\10 )*10
          >>
          That will definitely work, but I can't say I've ever like how "\"
          division does the casting to the integer.
          I'm not sure that gives the desired result when number is already a multiple of
          10, say 50 or 60, for instance. It depends on what is wanted in that case.


          Comment

          • =?ISO-8859-1?Q?G=F6ran_Andersson?=

            #6
            Re: How to find the next set of ten of a number?

            Lloyd Sheen wrote:
            Robert Scheer wrote:
            >Hi.
            >>
            >Suppose I have a number 55. The next exact set of ten will be 60. If
            >my number is 72 the next exact set of then will be 80 and so on. Is
            >there any function that can find the next set of ten of a given
            >number? I read abou the Math class, but it seems that it doesn't have
            >such a function.
            >>
            >Regards,
            >Robert Scheer
            >
            There is no function to do that but this will work:
            >
            Dim number as integer = 55
            dim result as integer = ((number+10)\10 )*10
            >
            Hope this helps
            LS
            That depends. The question doesn't define what the next exact set of ten
            would be for all numbers. If the number is at the beginning of an exact
            set of ten, and the expression should then return that set instead of
            the next, you should add 9 instead of 10:

            Dim number As Integer = 50
            Dim result As Integer = ((number + 9) \ 10) * 10

            --
            Göran Andersson
            _____
            Göran Anderssons privata hemsida.

            Comment

            • =?ISO-8859-1?Q?G=F6ran_Andersson?=

              #7
              Re: How to find the next set of ten of a number?

              rowe_newsgroups wrote:
              I can't say I've ever like how "\"
              division does the casting to the integer.
              It doesn't do any casting, it's just an integer division.
              I've found that many
              programmers (especially junior level) don't know about that feature
              and it can lead to some very confused maintenance programmers. For
              that reason I highly recommend that whenever you use that feature, you
              put in a comment to make sure future developers know what's going on.
              It can be at least as confusing how the / operator actually does casting
              in VB. In many other languages the operator is overloaded to use the
              type of the operands, but in VB it always casts the operands to Double.

              Your concern is well grounded, however. We can't expect VB programmers
              to have (or be able to obtain) the knowledge of more than the most basic
              concepts of the language, so anything unusual should not be used in the
              code. ;)

              --
              Göran Andersson
              _____
              Göran Anderssons privata hemsida.

              Comment

              • rowe_newsgroups

                #8
                Re: How to find the next set of ten of a number?

                I can't say I've ever like how "\"
                division does the casting to the integer.
                >
                It doesn't do any casting, it's just an integer division.
                Yeah, I wrestled with what to put, and finally decided that calling it
                "casting" would work. Not sure why "integer division" escaped me!

                Thanks,

                Seth Rowe [MVP]

                Comment

                • Steve Gerrard

                  #9
                  Re: How to find the next set of ten of a number?

                  rowe_newsgroups wrote:
                  >>I can't say I've ever like how "\"
                  >>division does the casting to the integer.
                  >>
                  >It doesn't do any casting, it's just an integer division.
                  >
                  Yeah, I wrestled with what to put, and finally decided that calling it
                  "casting" would work. Not sure why "integer division" escaped me!
                  >
                  There are those who understand why (4.5 \ 1.5) produces 2, and those who don't.
                  :)




                  Comment

                  • Michael D. Ober

                    #10
                    Re: How to find the next set of ten of a number?

                    "Steve Gerrard" <mynamehere@com cast.netwrote in message
                    news:lJSdnVeUfO ASTxbVnZ2dnUVZ_ t_inZ2d@comcast .com...
                    rowe_newsgroups wrote:
                    >>>I can't say I've ever like how "\"
                    >>>division does the casting to the integer.
                    >>>
                    >>It doesn't do any casting, it's just an integer division.
                    >>
                    >Yeah, I wrestled with what to put, and finally decided that calling it
                    >"casting" would work. Not sure why "integer division" escaped me!
                    >>
                    >
                    There are those who understand why (4.5 \ 1.5) produces 2, and those who
                    don't. :)
                    (4.5 \ 1.5) should generate at least a compiler warning since neither number
                    is an integer.

                    Mike.


                    Comment

                    • Cor Ligthert[MVP]

                      #11
                      Re: How to find the next set of ten of a number?

                      Second try,

                      Hi Robert,

                      A typical homework question as very much developpers forget the Mod.
                      However, as there are so many questions give, I break as well the rules.

                      55 + 10 - 55 Mod 10

                      Cor

                      "Robert Scheer" <rbscheer@my-deja.comschreef in bericht
                      news:c71876ff-ea00-42bb-977a-b83d579e6dac@f3 6g2000hsa.googl egroups.com...
                      Hi.
                      >
                      Suppose I have a number 55. The next exact set of ten will be 60. If
                      my number is 72 the next exact set of then will be 80 and so on. Is
                      there any function that can find the next set of ten of a given
                      number? I read abou the Math class, but it seems that it doesn't have
                      such a function.
                      >
                      Regards,
                      Robert Scheer

                      Comment

                      • Cor Ligthert[MVP]

                        #12
                        Re: How to find the next set of ten of a number?

                        typo as so often but this one is to crazy

                        questions = answers

                        "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschre ef in bericht
                        news:eQWHC$77IH A.3260@TK2MSFTN GP03.phx.gbl...
                        Second try,
                        >
                        Hi Robert,
                        >
                        A typical homework question as very much developpers forget the Mod.
                        However, as there are so many questions give, I break as well the rules.
                        >
                        55 + 10 - 55 Mod 10
                        >
                        Cor
                        >
                        "Robert Scheer" <rbscheer@my-deja.comschreef in bericht
                        news:c71876ff-ea00-42bb-977a-b83d579e6dac@f3 6g2000hsa.googl egroups.com...
                        >Hi.
                        >>
                        >Suppose I have a number 55. The next exact set of ten will be 60. If
                        >my number is 72 the next exact set of then will be 80 and so on. Is
                        >there any function that can find the next set of ten of a given
                        >number? I read abou the Math class, but it seems that it doesn't have
                        >such a function.
                        >>
                        >Regards,
                        >Robert Scheer
                        >

                        Comment

                        Working...