Reputation: 688
I want to store the floating point number into sql database, but when I try to store the database asp.net code will convert the orginal number into other. eg) If I give 1.1 in textbox then it will stored in database 1.1000000238418579
When I drag the procedure the following class created.
[global::System.Data.Linq.Mapping.ParameterAttribute(Name="ServiceFee", DbType="Float")] System.Nullable<double> serviceFee,
SQL column Datatype
serviceType float;
Upvotes: 0
Views: 1117
Reputation: 4017
The closest representation of 1.1 in single-precision floating point is:
0 01111111 00011001100110011001101
That in decimal is
1
* 2^(127-127)
* (1 + (1 / 16 + 1 / 32 + 1 / 256 + 1 / 512 + 1 / 4096 + 1 / 8192 + 1 / 65536 + 1 / 131072 + 1 / 1048576 + 1 / 2097152 + 1 / 8388608)
) = 1.10000002384185791015625
If you "really" want to store 1.1, you have to use decimal.
Upvotes: 2
Reputation: 4263
Use the decimal data type to store numbers with decimals when the data values must be stored exactly as specified.
https://msdn.microsoft.com/en-us/library/ms187912(v=sql.105).aspx
Upvotes: 1