kolin kolin - 1 year ago 125
Vb.net Question

Decimal stored in database returned to .net Profile as rounded decimal

I have a custom .net profile which stores a decimal value in an SQL Table

Column decCode = Numeric (3,1)

The value stored is

My profile property in web.config is

<add name="decCode" provider="SqlProfile" customProviderData="decCode,Decimal" type="System.Decimal" />

When I execute a
the value always seems to be rounded up. (ProfileBase is not inherited, its the standard aspnet profile class)

As an example :
(in DB as 0.8)

Dim dec As Decimal = CType(pc.GetPropertyValue("decCode"), Decimal) === 1D
Dim a1 As String = String.Format("{0}: {1}", "G", dec.ToString("G")) === 1
Dim a2 As String = String.Format("{0}: {1}", "C", dec.ToString("C")) === £1.00
Dim a3 As String = String.Format("{0}: {1}", "E04", dec.ToString("E04")) === 1.0000E+000
Dim a4 As String = String.Format("{0}: {1}", "F", dec.ToString("F")) === 1.00
Dim a5 As String = String.Format("{0}: {1}", "N", dec.ToString("N")) === 1.00
Dim a6 As String = String.Format("{0}: {1}", "P", dec.ToString("P")) === 100.00%
Dim a7 As String = dec.ToString() === 1
Dim a8 As String = dec.ToString("0.0") === 1.0

Where as if I get the value of decCode using linq

return (_context.pUserProfiles.Where(p => p.UserId == GUID).FirstOrDefault().decCode).ToString()

i get 0.8

how can I use the
to return me the correct decimal?

Answer Source

You must change the DECIMAL to DOUBLE in "customProviderData" and the "cType", as follows:

 <add name="decCode" provider="SqlProfile" customProviderData="decCode,Double" type="System.Double" />


  Dim dec As Double = CType(pc.GetPropertyValue("decCode"), Double)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download