Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

VB.net Get the Next Value of 10

Good Day

Experts:

I am having a bit of difficulty working through this seemingly "easy" idea I need to accomplish.
I have an integer variable and need to find the next multiple of 10.  So 7 would be 10, 13 would be 20, 27 would be 30 and so on.  

Can anyone help me with how I might be able to programatically figure this out?

Thanks,
jimbo99999
0
Jimbo99999
Asked:
Jimbo99999
  • 4
  • 2
  • 2
2 Solutions
 
QuintainTCommented:
How about
add 9
divide by 10
take the integer amount
multiply by 10.
I'll work out the code if you like. Just shout...
0
 
hongjunCommented:
Try this
    Sub Main()
        Console.WriteLine(GetNextMultipleOfTen(7))
        Console.WriteLine(GetNextMultipleOfTen(13))
        Console.WriteLine(GetNextMultipleOfTen(27))
    End Sub 
    Public Function GetNextMultipleOfTen(ByVal i As Integer)
        Dim j As Integer = i + 10
        j = Math.Truncate(j / 10)
        j = j * 10
        Return j
    End Function

Open in new window

0
 
hongjunCommented:
To correct,


    Sub Main()
        Console.WriteLine(GetNextMultipleOfTen(7))
        Console.WriteLine(GetNextMultipleOfTen(10))
        Console.WriteLine(GetNextMultipleOfTen(13))
        Console.WriteLine(GetNextMultipleOfTen(27))
    End Sub 
    Public Function GetNextMultipleOfTen(ByVal i As Integer)
        Dim j As Integer = i + 9
        j = Math.Truncate(j / 10)
        j = j * 10
        Return j
    End Function

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jimbo99999Author Commented:
Ok, that would be great...
Thanks
0
 
hongjunCommented:
Only see QuintainT comment .
Sorry about that.
0
 
QuintainTCommented:
hongjun's code looks like it should work so I'd go with that. (I'd have done it slighly differently, but no better...:O)
0
 
hongjunCommented:
QuintainT deserves the effort too for the quick pseudocode posted.
0
 
Jimbo99999Author Commented:
I split up the points as hongjun came up with the on paper logice and QuintainT for the code.

Thanks for your efforts,
jimbo99999
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now