• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Didving UInt64 in vb.net

Hi

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.

Thanls
0
LuckyLucks
Asked:
LuckyLucks
  • 2
2 Solutions
 
deightonCommented:
       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)

0
 
deightonCommented:
basically you need to do the

System.Convert.ToDouble(l1)

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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now