|
-
Aug 5th, 2017, 10:56 AM
#1
Thread Starter
Lively Member
[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
Last edited by danzey; Aug 6th, 2017 at 02:01 AM.
-
Aug 5th, 2017, 11:47 AM
#2
Re: [help code] retrieve the integer value after dividing by a number
-
Aug 5th, 2017, 02:19 PM
#3
Thread Starter
Lively Member
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.
-
Aug 5th, 2017, 02:22 PM
#4
Re: [help code] retrieve the integer value after dividing by a number
Try:
Code:
intValue = Cint(Math.Floor(10/3))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 5th, 2017, 02:27 PM
#5
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)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 5th, 2017, 04:34 PM
#6
Thread Starter
Lively Member
Re: [help code] retrieve the integer value after dividing by a number
 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?
-
Aug 5th, 2017, 04:39 PM
#7
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 5th, 2017, 07:40 PM
#8
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.
My usual boring signature: Nothing
 
-
Aug 6th, 2017, 01:59 AM
#9
Thread Starter
Lively Member
Re: [resolved] retrieve the integer value after dividing by a number
thank you very much! it works!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|