2016-08-11 8 views
0

としてプロフィール.NETに戻った私は、格納された値が0.8小数点が丸い進

マイプロファイルプロパティでSQLの表に

Column decCode = Numeric (3,1) 

を小数点値を格納するカスタム.NETプロファイルを持っています私はProfileBase.GetPropertyValue("decCode")値を実行すると、web.configファイルに

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

は常に切り上げているようです。例として

(ProfileBaseは、標準ASPNETプロファイルクラス、継承されない): (DB 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 

どこLINQ

return (_context.pUserProfiles.Where(p => p.UserId == GUID).FirstOrDefault().decCode).ToString() 
を用いdecCodeの値を取得する場合のように

は、私は私に正しい小数を返すためにProfileBase.GetPropertyValueを使用する方法

0.8を取得しますか?

+0

はDOUBLE代わりにctype関数(でDECIMALを使用してください)。 –

+0

'Dim dec As Double = CType(pc.GetPropertyValue(" decCode ")、Double)' ===これは1.0として表示されます – kolin

+1

customProviderDataもダブルに更新しましたか? –

答えて

1

次のようにあなたは、 "customProviderData" と "cTypeと" にDoubleにDECIMALを変更する必要があります。

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

Dim dec As Double = CType(pc.GetPropertyValue("decCode"), Double) 
関連する問題