Solved

# Didving UInt64 in vb.net

Posted on 2006-04-24
336 Views
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
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)

0

LVL 18

Expert Comment

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

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
0

## Featured Post

### Suggested Solutions

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 (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. 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…