I have rounding problems when editing or inserting a new record in float type fields.
e.g. I have a cursor running an agrregate SQL statement. I have a calculated field Sum(DFactor*Cost). DFactor gets values -1,1 and values of Cost in the table have 2 digits. I get these values in a variable e.g. @.FCost. Then I round @.FCost=Round(@.FCost,2).
When I try to inert this value to a new record again I'using Round(@.FCost,2).
However in a lot of records a lot of digits are stored.
I have the same probelm when trying to insert values from MSAccess by ODBC. Although I'm using CLng(@.FCost*100)/100 in order to have 2 digits, a lot of demical values are created.
What is the best practise in order to solve this problem?
Regards,
ManolisIf you are using a FLOAT column to store data of type MONEY, that's a problem. If you are using a FLOAT column to store data of type DECIMAL (x, 2), that's also a problem. Is your underlying problem one of datatype, not actually rounding?
-PatP|||Although I'm using CLng(@.FCost*100)/100 in order to have 2 digits, a lot of demical values are created.The result will have decimals. You need this: CLng(@.FCost*100/100)
Showing posts with label float. Show all posts
Showing posts with label float. Show all posts
Wednesday, March 7, 2012
Saturday, February 25, 2012
round up
X is a float and I need to perform x/10 and round the result up to the integer. So if result is 0.4 -> 1, if 1.1 -> 2.
How can I do this with SQL?
? Use the CIELING function: SELECT CIELING(x/10) FROM YourTable -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <JIM.H.@.discussions.microsoft.com> wrote in message news:4165a8e6-3d64-4db1-9c4b-1cec7040f35a@.discussions.microsoft.com... X is a float and I need to perform x/10 and round the result up to the integer. So if result is 0.4 -> 1, if 1.1 -> 2. How can I do this with SQL?|||use CEILING
select ceiling(0.4),ceiling(1.1)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
|||you can use the round function
For Example:
SELECT round(4.9, 0)
Check out BOL for more details
AWAL
|||Not really, OP wanted 2 for 1.1
round gives 1
Denis the SQL Menace
http://sqlservercode.blogspot.com/
round up
X is a float and I need to perform x/10 and round the result up to the integer. So if result is 0.4 -> 1, if 1.1 -> 2.
How can I do this with SQL?
SELECTCEILING(X/10)AS numRoundup
FROM yourTable
Subscribe to:
Posts (Atom)