T-SQL ROUND(decimal, Int) Vs C# Round(Decimal, Int32)
Jan 30, 2006
Anybody noticed that SQL Server rounds up if the value is half way
between two rounded values, but C#'s Decimal.Round(Decimal,Int32)
rounds to nearest even number?
[color=blue]
>From MSDN: "When d is exactly halfway between two rounded values, the[/color]
result is the rounded value that has an even digit in the far right
decimal position. For example, when rounded to two decimals, the value
2.345 becomes 2.34 and the value 2.355 becomes 2.36. This process is
known as rounding toward even, or rounding to nearest."
I perform the same calculation sometimes on the web server in C# and
sometimes at the database in T-SQL, but want to get the same result
from both calculations. Could anybody offer any strategies for dealing
with this?
Hi all, I am sorry if i am posting this error in an inappropriate froum. Well in my asp.net intranet web application i want to enter a number to the database(sql sever 2005) that has a column(schoolkm) whose type is decimal(9, 2). Now if i want to enter the value 1.5 in the text box and enter that value to the database through interface then that value automatically rounds to 2. But when i get into the table and enter that value by hand then that value enters perfectly i.e. without rounding of. I want to know the reason and how can i cure this problem. Regards & thanks in advance
I am working with a legacy SQL server database from SQL Server 2000. I noticed that in some places that they use decimal data types, that I would normally think they should be using integer data types. Why is this does anyone know?
Example: AutomobileTypeId (PK, decimal(10,0), not null)
I am creating a table on SQL Server. One of the columns in this new table contains whole integer as wells as decimal values (i.e. 4500 0.9876). I currently have this column defined as Decimal(12,4). This adds 4 digits after the decimal point to the whole integers. Is there a data type that will have the decimal point only for decimal values and no decimal point for the whole integers?
I would like to cast (convert) data type decimal(24,4) to decimal(21,4). I could not do this using standard casting function CAST(@variable as decimal(21,4)) or CONVERT(decimal(21,4),@variable) because of the following error: "Arithmetic overflow error converting numeric to data type numeric." Is that because of possible loss of the value?
I wanted to convert a dataset from vb.net (2.0) to an .XLS file, by MS Jet. My national standard is using decimal commas, not decimal points for numbers signing the beginning of decimal places. But the MS Jet Engine uses decimal point,in default. Therefore, in the Excel file only string formatted cells can welcome this data, not number formatted. How can I solve or get around this problem? (with jet if it possible) iviczl
I'd like to convert a Decimal value into a string so that the entireoriginal value and length remains intact but there is no decimal point.For example, the decimal value 6.250 is selected as 06250.Can this be done?
I am designing some reports for a German branch of my company and need to replace decimal point with a comma and the thousand comma seperator with a decimal point.
e.g. ‚¬1,500,123.00 to ‚¬1.500.123,00
Is there a property that I can change in the report designer to allow this to happen or is this something I need to convert in a Stored Proc.
I am having a file in which amount fields are given in a Packed Decimal format. Can anyone suggest me how I can read this data element from the file and convert it into SQL decimal datatype.
File is a fixed length. All the amount fields are given in Packed Decimal Format and rest of the fields are given in text format. How can i identify and convert only those packed decimals using SQL/.Net.
Example : a row in a file that has some packed decimals 158203508540188236252EUR20BZK0030 Å“& 20060715 0001010100010101
I want to do a simple thing but it seems to be behaving not as i am expectingI want to round number either up or down....e.g: 4.3 should round to 4 4.7 should round to 5when i use the round function like this: 83/17=4.88round( 83/17 , 0 ) it gives the answer as 4....when i was expecting it to be 5.... i know there is a ceiling function...but depending on the value of the division sometimes i want it to round up and sometimes round down. how can i do this? hope this makes sense. thanks
Has anyone been experiencing problems with rounding to 2 decimal places in SQL 7? I have a bunch of queries that generate web reports. Under 6.5 everything was fine. Now under 7.0 any number that needs to be rounded to 2 decimals is actually giving me several decimal places.
Here is a simplified version of what I am doing: DECLARE @x real DECLARE @y real SELECT @x = 223.1 SELECT @y = 59.7
SELECT ROUND((@x/@y),2)
Result should be 3.74. But instead I am getting 3.7400000000000002
If anybody has heard if Microsoft has declared this as a known bug please let me know.
if if i have time as 1:15 min means it has to show 1:15,if i have 1:20 min it has too be rounded and it has to show 1:30 min. can any one give me query for this thanks in anvance
There is a filed in a table of type decimal(12, 8)
when running a select query on this table for this field i.e. select field1 from table1
the data is shown like: 102.12500000 104.12500000
And therefore the report shows the same figure.
How do I get this field to show up in the report as 4 decimal places. i.e. 102.1250 104.1250
Tried the properties of the cell to format the text into a number but there is only 2 decimal places there. Even tried the expression by using Rnd(field1). This does not seem to do what I am after.
How do I write sql syntax to round the last digit. For example, 12.152 should be 12.15. My current sql syntax does not round the last digit as follows:
Select tblARInvoiceDetail.UnitPrice * tblARInvoiceDetail.Quantity AS ChargeBeforeDiscount FROM tblARInvoices INNER JOIN tblARInvoiceDetail ON tblARInvoices.ARInvoiceID = tblARInvoiceDetail.ARInvoiceID
The tblARInvoiceDetail.UnitPrice column is numeric;length 9;precision 18 The Quantity column is integer;length 4; precision 10;scale 0
I am using sql statement to save data in SQL SERVER but even i did not apply any round function it is automatically rounding up. e.g. 3.56 when i see it in database it is 4 how can i avoid this rounding? I am using MS Access as front end.
I have already summed the values and this below query sum the values and returns zero if there are no values. How can I roundoff the values for these columns.