显示标签为“points”的博文。显示所有博文
显示标签为“points”的博文。显示所有博文

2012年3月29日星期四

Float type

I inhereted a database that has a lot of Float type columns. Typically
these columns hold decimal-type data rounded to four decimal points
such as:
987.1234
Is Float the appropriate data type for use with these types of columns?Float is generally referred to as an approximate datatype (approximate for the 10.base system, which
us humans tend to use). This mean that a value you input might not be the one which is stored, just
try below:
SELECT CAST(3.1 AS float)
If above is not acceptable, then use NUMERIC with a scale of 4 instead, like:
SELECT CAST(3.1 AS numeric(9,4))
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"laurenq uantrell" <laurenquantrell@.hotmail.com> wrote in message
news:1135913496.671119.91530@.g49g2000cwa.googlegroups.com...
>I inhereted a database that has a lot of Float type columns. Typically
> these columns hold decimal-type data rounded to four decimal points
> such as:
> 987.1234
> Is Float the appropriate data type for use with these types of columns?
>

2012年3月27日星期二

FLOAT

I want to use only float datatype but the problem is that it return more
than two decimal, I want to minimize to two decimal points? I don't want to
use decimal datatype... I only wanna use float....
The result should looks like
152254.45
but now it's giving me.
152254.45123232363
Any solution ?
Thanks
On Wed, 2 Nov 2005 11:19:15 -0500, Rogers wrote:

>I want to use only float datatype but the problem is that it return more
>than two decimal, I want to minimize to two decimal points? I don't want to
>use decimal datatype... I only wanna use float....
>The result should looks like
>152254.45
>but now it's giving me.
>152254.45123232363
>Any solution ?
Hi Rogers,
No, of course not. The FLOAT datatype is designed to *not* have an exact
and limited number of decimals. The datatypes that are designed to offer
a fixed number of decimal places are decimal and numeric.
Saying "I want to have two decimal points but I don't want to use
decimal datatype... I olnly wanna use float" is like saying "I want to
travel by air but I don't want to use a plane... I only wanna use a
boat".
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||I only want to use float datatype because I have to frequenly convert the
database into Access 97 and Access doesn't support decimal and numeric
datatype.
Thanks
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:q43im1ddb79j8bmre6kugqrjo7nem75f6r@.4ax.com...
> On Wed, 2 Nov 2005 11:19:15 -0500, Rogers wrote:
>
> Hi Rogers,
> No, of course not. The FLOAT datatype is designed to *not* have an exact
> and limited number of decimals. The datatypes that are designed to offer
> a fixed number of decimal places are decimal and numeric.
> Saying "I want to have two decimal points but I don't want to use
> decimal datatype... I olnly wanna use float" is like saying "I want to
> travel by air but I don't want to use a plane... I only wanna use a
> boat".
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
|||Rogers wrote:
> I only want to use float datatype because I have to frequenly convert
> the database into Access 97 and Access doesn't support decimal and
> numeric datatype.
>
Access 2003 ( I realize this is not Access 97 - but that version is almost 9
years old) has a Number Data Type, which can then be qualified with the
"Number" type. Choice abound:
- Byte
- Integer
- Long Integer
- Single
- Double
- Replication ID
- Decimal - which has precision and scale to match that used by SQL Server
David Gugick
Quest Software
|||On Wed, 2 Nov 2005 14:47:07 -0500, Rogers wrote:

>I only want to use float datatype because I have to frequenly convert the
>database into Access 97 and Access doesn't support decimal and numeric
>datatype.
Hi Rogers,
I just did a quick test - create a table with a decimal(9,2) column in
SQL Server, then create a linked table in Access 97. Access defines the
column as double. I could enter and retrieve data without any problems
(other than data with more than two decimals being rounded).
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
sql

2012年3月11日星期日

Fixed decimal convertion

I am trying to show latitude and longitude with 5 decimal points. Now its showing (for example: 55.744025477, -4.1256633333333 etc.). How do I get data in 5 decimal points?

Your help with example would be appreciated.

aspx code:

<asp:GridView ID="GridView1" runat="server" DataSourceID="odsGPS" AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="False" CellPadding="1" CellSpacing="1" BackColor="White" GridLines="None"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" PageSize="20" Width="100%" Font-Size="8pt"
OnLoad="GridView1_Load" >
<Columns>
<asp:TemplateField HeaderText="Show">
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" onclick="MarkerForThisRow(this);" ToolTip="Click to show on map." runat="server" OnCheckedChanged="CheckBox2_CheckedChanged" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>

<asp:BoundField DataField="Latitude" HeaderText="Latitude ( ° )" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>


<asp:BoundField DataField="Longitude" HeaderText="Longitude ( ° )" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>

In your <asp:BoundField /> for the Latitude, add the following:

DataFormatString="{0:F5}"

F represents a fixed decimal, and 5 represents the number of decimal places

|||

On your gridview open the gridview task with clicking little arrow on the right upper corner.

Then click Edit Columns
Then select your field "Latitude",
Then on the right, scroll down and come to Data section.
Change the dataFormatString as {0:N5}
Also you will see another property under Behavior section which is "HtmlEncode" make it false...

Let me know if it does not work...


|||

Thanks a lot guys for your help.

In the mean time, I found another way to do it. Using Convert.ToDecimal in a Item Template also does the job.

<asp:TemplateField HeaderText="Latitude ( ° )">
<ItemTemplate>
<%# Convert.ToDecimal(Eval("Latitude")).ToString("0.00000") %>
</ItemTemplate></asp:TemplateField>

|||

Hiavci,

It did not work in my case.

|||

Hi,

It must work.I already tried and it's working.

Did you make HTMLEncode=False ?|||

I did. But may be I am missing something else.

<asp:BoundField DataField="Latitude" HeaderText="Latitude " DataFormatString="{0:N5}" HtmlEncode="False" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>

|||

Datafield "Latitude" is not defined varchar or text in the database,right?
Can you check its type in the database?

|||

GPSID int Unchecked
VehicleID int Unchecked
Latitude varchar(50) Unchecked
Longitude varchar(50) Unchecked
GPSTime datetime Checked
ServerTime datetime Unchecked
Valid bit Unchecked

|||

If those two are varchars, you will not be able to write them as decimals.That property we said will not work. You have to change their type to int, or decimal.

2012年3月9日星期五

fix DBCC CHECKCATALOG errors

How to fix system tables integrity errors? DBCC CHECKCATALOG points
that exists objects (in sys.columns) without depend views. In SQL 2000 I can
edit direct sysobject table. How delete orphaned objects in SQL 2005? Only
way is copy data to new database?I wouldn't think editing sysobjects is a real good idea, unless you're very
(very) sure.
However, since CHECKCATALOG is part of CHECKDB, I would assume you would
used CHECKDB to repair any problems.
"Waldemar Grzywiñski" <waldemarg@.autograf.pl> wrote in message
news:evNoNT%23JIHA.5684@.TK2MSFTNGP06.phx.gbl...
> How to fix system tables integrity errors? DBCC CHECKCATALOG points
> that exists objects (in sys.columns) without depend views. In SQL 2000 I
> can edit direct sysobject table. How delete orphaned objects in SQL 2005?
> Only way is copy data to new database?
>