Adblock breaks this site

Rounding up

Discussion in 'Programming General' started by 5cript, Apr 13, 2007.

  1. 5cript

    5cript Active Member

    Joined:
    Jan 22, 2007
    Posts:
    138
    Referrals:
    1
    Sythe Gold:
    0
    Rounding up

    I just need a code for rounding up in visual basic. If there isnt is there someother way i could? (BTW, my code i mean a symbol) Here is what im trying to do
    Code:
    (aa - b) /f 
    when im calculating it, it ends in .13 for example and i want it to round up no matter what it ends in. Thanks for your help!
     
  2. speljohan

    speljohan Guru
    Visual Basic Programmers

    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0
    Rounding up

    declare the variable as a Single instead of an integer.
     
  3. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    Rounding up

    somthign like

    Math.Round(6.69696969 - 0.005, 2)

    For the generic case:

    Function Truncate(ByVal value As Double, ByVal decimals As Integer) As Double

    Return Math.Round(value - 0.5 / Math.Pow(10, decimals), decimals)

    End Function



    also you can use some formatting

    take a look at this

    http://msconline.maconstate.edu/tutorials/VBNET/VBNET01/vbnet01-08.aspx
     
  4. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Rounding up

    round()
    int()
     
  5. speljohan

    speljohan Guru
    Visual Basic Programmers

    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0
    Rounding up

    don't use the functions covey suggested. They're vb6 functions and work very slowly compared to the built in functions of the framework.
     
< Ceating dlls | need tutorial lesson!! >


 
 
Adblock breaks this site