Didving UInt64 in

Posted on 2006-04-24
Last Modified: 2012-05-05

I have the numerator as a Unit64 number and likewise of denominator. How can I didvde them to get a 2 decimal number? FOr some reason doesntlike the / ,saying this operator is not defined for system.UInt64.

Question by:LuckyLucks
    LVL 18

    Assisted Solution

           Dim l1 As System.UInt64
            Dim l2 As System.UInt64

            l1 = System.Convert.ToUInt64(666)
            l2 = System.Convert.ToUInt64(34)

            Dim d As Decimal = CType(System.Convert.ToDouble(l1) / System.Convert.ToDouble(l2), Decimal)

    LVL 18

    Expert Comment

    basically you need to do the


    to go to a double type which should always hold the unsigned 8 byte integer, this will be ok unless you are doing something with remainders, where precision errors might creep in.  But for two decimal places of accuracy, you will be ok.
    LVL 85

    Accepted Solution

    This works fine in VB.Net 2005 Express:

            Dim l1 As System.UInt64 = 666
            Dim l2 As System.UInt64 = 34
            Dim d As Decimal = l1 / l2
            Dim strD As String = d.ToString("#0.00")
            Debug.Print(strD) ' 19.59

    But in VB.Net 2003 it complains...and needed:

            Dim l1 As System.UInt64 = System.Convert.ToUInt64(666)
            Dim l2 As System.UInt64 = System.Convert.ToUInt64(34)
            Dim d As Decimal = System.Convert.ToDecimal(l1) / System.Convert.ToDecimal(l2)
            Dim strD As String = d.ToString("#0.00")
            Debug.WriteLine(strD) ' 19.59

    Why are you using UInt64?

    The Decimal value type represents decimal numbers ranging from:

        -79,228,162,514,264,337,593,543,950,335 to 79,228,162,514,264,337,593,543,950,335

    which easily covers these numbers.

    This worked fine in both VB.Net 2003 and VB.Net 2005:

            Dim l1 As Decimal = 666
            Dim l2 As Decimal = 34
            Dim d As Decimal = l1 / l2
            Dim strD As String = d.ToString("#0.00")
            Debug.Print(strD) ' 19.59

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now