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

  • Thread starter Thread starter Robert Scheer
  • Start date Start date
R

Robert Scheer

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
 
Robert said:
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
 
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]
http://sethrowe.blogspot.com/
 
Lloyd said:
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
 
rowe_newsgroups said:
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. ;)
 
I can't say I've ever like how "\"
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]
 
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
 
Back
Top