Results 1 to 9 of 9

Thread: [resolved] retrieve the integer value after dividing by a number

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2017
    Posts
    96

    Resolved [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.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: [help code] retrieve the integer value after dividing by a number


  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2017
    Posts
    96

    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.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: [help code] retrieve the integer value after dividing by a number

    Try:

    Code:
    intValue = Cint(Math.Floor(10/3))

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2017
    Posts
    96

    Re: [help code] retrieve the integer value after dividing by a number

    Quote Originally Posted by .paul. View Post
    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?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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...

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    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

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2017
    Posts
    96

    Resolved 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
  •  



Click Here to Expand Forum to Full Width