
What is a decimal?
Hi,<BR><BR>The SQL Server manual says:<BR><BR>'The decimal data type stores an exact representation of the number; there is no approximation of the stored value.'<BR><BR>What exactly does this mean?<BR><BR>The following script...<BR><BR>declare @dec1 as decimal<BR>set @dec1 = 10/3<BR>print @dec1<BR><BR>gives an output of '3'! That doesn't seem very exact to me.<BR><BR>Cheers,<BR><BR>I.

RE: What is a decimal?
decimal takes two values if you read on number of integer and number of 'decimal' unless you declare them it defaults to integer only!<BR><BR>So<BR><BR>declare @dec1 as decimal(5,5) ' as an example

RE: What is a decimal?
It has evaluated the division of two integers and given you the integer result. If you want to see a more exact answer, try 10.0/3.0.

And...
see WK's reply as well. DECIMAL by itself won't do you much good.

RE: And...
Cheers for the reply.<BR><BR>declare @dec1 as decimal(5,5)<BR>set @dec1 = 10/3<BR>print @dec1<BR><BR>Now I get...<BR><BR>'Arithmetic overflow error converting numeric to data type numeric.'<BR><BR>So if a user tries to enter '10/3' into the database, I need to put up a request asking them to try a value which doesn't have a recurring decimal?!<BR><BR>

The second number...
cannot be the same or larger than the first. Lookup scale and precision in the documentation. Try DECIMAL(10, 5) or even DECIMAL(6,5). Also, you still need 10.0/3.0 or you'll still get 3 (with more decimal points at the end).

RE: The second number...
OK, so now I'm getting somewhere.<BR><BR>declare @dec1 as decimal(30,25)<BR>set @dec1 = 10.0/3.0<BR>print @dec1<BR><BR>This gives 3.3333330000000000000000000!<BR><BR><BR>Anyhow, what is the difference between a decimal's 'an exact representation of the number' and float and real's approximation of a number?<BR><BR>Cheers,<BR><BR>I.

RE: The second number...
From Books OnLine (check out the first sentence especially):<BR><BR>Approximate numeric data types do not store the exact values specified for many numbers; they store an extremely close approximation of the value. For many applications, the tiny difference between the specified value and the stored approximation is not noticeable. At times, though, the difference becomes noticeable. Because of the approximate nature of the float and real data types, do not use these data types when exact numeric behavior is required, such as in financial applications, in operations involving rounding, or in equality checks. Instead, use the integer, decimal, money, or smallmoney data types.

RE: The second number...
Yeah I read that but it doesn't make all that much sense to me that's all.

profound
You see, in modern mathematics, 'an extremely close approximation' doesn't mean a whole lot by itself.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

