this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Thursday, February 18, 2010

Get Quotient and reminder in single statement

For the calculation purpose we need to calculate Quotient and reminder. We mostly uses divide and then mod operation to get quotient and remainder respectively but .net has provided in built function in the Math class that performs all this in the one statement.

Let’s take an example.

Dim num As Integer = 100

Dim rim As Integer = 0

Dim qut As Integer = Math.DivRem(num, 3, rim)

In above code snippet, we have num and we want to divide it by 3 and at the same time we need remainder of it.

Math.DivRem function takes three arguments

331)Number you want to Divide, here we have num variable

332)Number by which you want to Divide (divisor),here we have 3

333) Variable where it will store remainder, here we have rim variable

Let me know, if you know anything better than this.

No comments: