[resolved] retrieve the integer value after dividing by a number
hello i would like a code to retrieve the integer value
example after dividing a number , i got 100,6 and i would like 100 (or 101 if it is possible)
it 's to integrate in numericupdown.value
thanks for your answer
Re: [help code] retrieve the integer value after dividing by a number
Re: [help code] retrieve the integer value after dividing by a number
i am a beginner i found round methode but i can't use it.Please help me with an example.
Re: [help code] retrieve the integer value after dividing by a number
Try:
Code:
intValue = Cint(Math.Floor(10/3))
Re: [help code] retrieve the integer value after dividing by a number
Here's a rounding example:
Code:
'to get the integer value and discard the fractional part
Dim intValue As Integer = CInt(Math.Floor(10 / 3))
MsgBox(intValue)
'to use banker's rounding
intValue = CInt(Math.Round((10 / 4), MidpointRounding.AwayFromZero))
MsgBox(intValue)
Re: [help code] retrieve the integer value after dividing by a number
Quote:
Originally Posted by
.paul.
Try:
Code:
intValue = Cint(Math.Floor(10/3))
so resuming,
i have this addition: numericupdown3.value = numericupdown1.value+ (Cint(Math.Floor((numericupdown2.value) /2))
am i right?
Re: [help code] retrieve the integer value after dividing by a number
That code will always round down. If you want midpoint rounding, see my second example...
Re: [help code] retrieve the integer value after dividing by a number
Another thing you can do is use the integer divide \, rather than the floating point divide /. This does the round down, too, so you can write:
Code:
numericupdown3.value = numericupdown1.value + numericupdown2.value \ 2
That gives you the same result, since it will also always round down.
Re: [resolved] retrieve the integer value after dividing by a number
thank you very much! it works!:wave: