float number

Last Post 11 Jan 2013 11:11 AM by awais9981. 4 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
dbandee
New Member
New Member

--
10 Jan 2013 07:15 AM
Good morning and Happy New year to every one!
I have an issue in one of my tables.
The table has few fields all of them are float (and should be by design)
We import values into the table from access.
I noticed that one value after import when i do select is in scientific notation
0.000075 shows in output of y select statement as -7.5E-05
Why is it like that? i tried updating the table with 0.00075 and it show up fine.
My concern is that it might show like that on the front end? or will it?
Am i over complicating this, is is normal behavior in sql server.

Thank you

awais9981
New Member
New Member

--
10 Jan 2013 02:44 PM
Hi,

Check the following link
http://msdn.microsoft.com/en-US/lib...80%29.aspx

it says that

The number is converted to a string of the form "-d.ddd…E+ddd" or "-d.ddd…e+ddd", where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. One digit always precedes the decimal point.

The precision specifier indicates the desired number of digits after the decimal point. If the precision specifier is omitted, a default of six digits after the decimal point is used.

The case of the format specifier indicates whether to prefix the exponent with an 'E' or an 'e'. The exponent always consists of a plus or minus sign and a minimum of three digits. The exponent is padded with zeros to meet this minimum, if required.


it seems to me that default string formats for float in SQL Server and .NET are same.:)

Best regards,
Muhammad Awais Akram
awais9981
New Member
New Member

--
10 Jan 2013 03:06 PM
[quote]
Posted By awais9981 on 10 Jan 2013 05:44 PM
Hi,

Check the following link
http://msdn.microsoft.com/en-US/lib...80%29.aspx

it says that

Fixed-point notation is used if the exponent that would result from expressing the number in scientific notation is greater than -5 and less than the precision specifier; otherwise, scientific notation is used. The result contains a decimal point if required and trailing zeroes are omitted. If the precision specifier is present and the number of significant digits in the result exceeds the specified precision, then the excess trailing digits are removed by rounding.

The exception to the preceding rule is if the number is a Decimal and the precision specifier is omitted. In that case, fixed-point notation is always used and trailing zeroes are preserved.

If scientific notation is used, the exponent in the result is prefixed with 'E' if the format specifier is 'G', or 'e' if the format specifier is 'g'.


when you use 0.000075( 7.5e-05) then exponent is -5 so in this case scientific notation is being used.
while when you use 0.00075( 7.5e-04) then exponent is -4 which is greater than -5. so in this case fixed-point notation is being used.

it seems to me that default string formats for float in SQL Server and .NET are same.:)

Best regards,
Muhammad Awais Akram
[/quote]
gunneyk
New Member
New Member

--
10 Jan 2013 05:23 PM
How data is displayed is totally up to the client and has no bearing how it is stored. If it is a Float datatype then it is stored as Float period. However if you used 3 different client apps to display the data it may (potentially) be displayed 3 different ways. So it is up to you (or really your app) to display any data in the format you desire.
awais9981
New Member
New Member

--
11 Jan 2013 11:11 AM
yes. you can override default format.
You are not authorized to post a reply.

Acceptable Use Policy