all groups > sql server programming > may 2007 >
You're in the

sql server programming

group:

truncate value of a float data type column to 4 decimal places


truncate value of a float data type column to 4 decimal places Cismail via SQLMonster.com
5/25/2007 7:19:22 PM
sql server programming: Hello,

I have a table that contains values with 16 decimal places in the Weight
column(table definition below).
How can I truncate these values to four decimal places???

CREATE TABLE [Detail] (
[Transaction] [varchar] (10) NULL ,
[LineNb] [int] NULL ,
[Weight] [float] NULL
) ON [PRIMARY]

example of data in weight column: 4.2999999999999998

I successfully ran the following commands in Query Analyzer but when I
displayed the table using the SELECT statement nothing changed.

UPDATE Detail SET Weight = CAST(Weight as decimal(15,4))
UPDATE Detail SET Weight = ROUND(Weight, 4,1)

Thank you for any help.

--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200705/1
Re: truncate value of a float data type column to 4 decimal places Mr Tea
5/25/2007 7:37:29 PM
Floats are inherantly inaccurate becuase of the way they are stored.

The data in your column is 4.3 but the float cannot store that accurately
and the closest you get is what you see here.
Some interfaces will round data like this automatically but in the rest of
cases you'll have to round it yourself on presentation.

Mr Tea


[quoted text, click to view]

RE: truncate value of a float data type column to 4 decimal places Nikhil chaturvedi
6/1/2007 4:00:00 AM
Dear,

You can use round(Number,digit up to roundoff) function to truncate value.
You can see ceiling () for it.

Regards

Nikhil Chaturvedi

[quoted text, click to view]
AddThis Social Bookmark Button