CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    36

    How can I round this Convert.ToInt64 number that will be returned

    Hello,

    I need to have this number rounded and have never done this before, so If you can help me that would be great.

    long mem1 = Convert.ToInt64(objPartition["Size"].ToString()) / 1024 / 1024 / 1024 + 0;

    Currently it is reporting 3GB and should be 4GB

    So this number must be close to 3.xxxx and need to be round up to 4.xx

    I found this on msdn, but dont understand how to make it work with my line of code.

    Math.Round(3.44, 1); //Returns 3.4.
    Math.Round(3.45, 1); //Returns 3.4.
    Math.Round(3.46, 1); //Returns 3.5.

    Thanks for your help,

    -Mike

  2. #2
    Join Date
    Oct 2004
    Location
    Rocket City
    Posts
    220

    Re: How can I round this Convert.ToInt64 number that will be returned

    If you change ", 1);" to ", 0);" your examples will all return 3.

  3. #3
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    Re: How can I round this Convert.ToInt64 number that will be returned

    Are you trying to round up? You could always use Math.Ceiling.

    See the below link, http://msdn.microsoft.com/en-us/library/zx4t0t48.aspx.

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

Featured