
Simple Rookie Data Type Question
When I look at the help for SQL Sever 2k, this is what I get for definitions of these two data types:<BR><BR>decimal:<BR>Fixed precision and scale numeric data from 10^38 +1 through 10^38 –1<BR><BR>float:<BR>Floating precision number data from 1.79E + 308 through 1.79E + 308.<BR><BR><BR>My question is, what is the difference between fixed and floating precision? And when should I consider using decimal, numeric, float, or real? The help file gives a small definition but no usable advice.<BR>

Not rookie...misunderstood by most
A fixed precision and scale numeric data field is, essentially, like using one of those printing calculators where you slide the decimal point setting (usually to 0, 1, 2, or F) to what you want and then, as you enter numbers, you don't bother putting in a decimal point. (And, for the purposes of this example, let's say this particular calculator can only print up to 10 digits wide.) So you push<BR>735<BR>+<BR>217<BR>=<BR>And you see an answer (if you set the switch to 2) of<BR>9.52<BR><BR>Very useful for adding up columns of dollars and cents without having to keep pushing the decimal point, no?<BR><BR>But consider: If you use such a calculator and *DO* put in a decimal point when you enter a number...it works fine. BUT it does *NOT* affect the number of digits after the decimal point in the result!<BR>7.32171<BR>+<BR>5.19224<BR>=<BR>Still displays just<BR>12.51<BR><BR>And, finally, if you try to enter<BR>77711177211222<BR>+<BR>Well, that's as far as you get. You get an error, indicating you entered too many digits. Yes?<BR><BR>Same thing with fixed precision (total number of digits available) and scale (number of digits after the decimal point) in various kinds of DBs.<BR><BR>That printing calculator is very much like a "precision 10, scale 2" field in a DB. <BR><BR>The advantage of such fields: No problems with rounding. (Well, so long as you don't do any multiplication or division, at least.)<BR><BR>The disadvantage of such fields: If you ever *do* have a number that needs more precision or more digits after the decimal point, you are out of luck.<BR><BR>FINALLY... You should be aware that VBScript is *NOT* capable of manipulating DECIMAL values. (Not quite true; the CURRENCY data type in VBS has *fixed* precision and scale of 19 and 4, if I figure it correctly...but you *can* get errors, then, converting from VBS currency to SQL DECIMAL if the scale and precision don't match 19 and 4.) <BR><BR>If you are working with monetary values that will only be added and subtracted, then fixed decimal is probably a fine way to go. Otherwise...well, it's the usual answer to all programming question: "It depends..."<BR><BR>

Great Explanation!
Much Appreciated! Do you teach courses anywhere? That's a better understanding and explanation than I ever received from any of my (small college) professors. :)<BR><BR>P.S. You were right about my script question yesterday about calling vbscript and javascript from each other client side. I started over and it worked fine. Obviously I had a typo somewhere that I didn't catch.
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

