Didving UInt64 in vb.net


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 vb.net doesntlike the / ,saying this operator is not defined for system.UInt64.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

       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)

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.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.