Integer Division


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Integer Division

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Posts
    1

    Integer Division

    I am new to the programming world. I understand integer division however my problem is why when you use integer division and the divisor is one is the result being rounded vice the integer value of the division.

    For, example when I enter the following code.

    'declare variable
    Dim intCommission as Integer

    'calculate commission
    intCommission = 2.78 \ 1

    'display commission
    me.uiCommissionLabel.text = intCommission

    VB.Net returns a result of 3 vice 2 in the commission label

    Was wondering if any one could explain this to me or lead me to correcting this problem. Thanks!

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    2.78 is getting rounded to the nearest integer value (3) when assigned to an Integer. If the value were 2.4, it would be rounded to 2. If you want to simply discard the fractional portion, use the Int() or Fix() functions.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. call function for button
    By angela_quests in forum VB Classic
    Replies: 2
    Last Post: 04-13-2007, 04:57 AM
  2. Physical Address of the NIC
    By eduardoms in forum Security
    Replies: 2
    Last Post: 05-06-2005, 10:26 AM
  3. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  4. Remainder of Integer Division
    By James Knowlton in forum .NET
    Replies: 2
    Last Post: 04-15-2001, 09:25 PM
  5. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center