CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    Cordoba, Argentina
    Posts
    71

    Roundup in Visual Basic

    I need to know wich is the round function in Visual Basic similar to Roundup of Microsoft Excel. ???

    In Excel this function round the decimal values of this way:
    Roundup(0.22,2)=0.22
    Roundup(0.221,2)=0.23
    Roundup(0.2201,2)=0.23

    always to up !!!!!

    This function exists in Visual Basic ????

    Thanks and Regards
    Sebastian

  2. #2
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228
    you can make a function like this:
    Code:
    Function Roundup(f As Single, precision As Integer) As Single
        Dim f2 As Single
        precision = 2
        f2 = FormatNumber(f, precision)
        If f > f2 Then f2 = f2 + 10 ^ -precision    'Maybe there's a better way for this...
        Roundup = f2
    End Function
    
    'Then use:
    Private Sub Form_Load()
    MsgBox Roundup(0.2201, 2)
    End Sub

Bookmarks

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

Click Here to Expand Forum to Full Width