نکات کاربردی

طبقه بندی موضوعی

آخرین مطالب

انواع داده تقریبی

پنجشنبه, ۲۳ فروردين ۱۳۹۷، ۰۱:۴۷ ب.ظ

The float and real data types are known as approximate data types. The behavior of float and real follows the IEEE 754 specification on approximate numeric data types.

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.

Avoid using float or real columns in WHERE clause search conditions, especially the = and <> operators. It is best to limit float and real columns to > or < comparisons.

The IEEE 754 specification provides four rounding modes: round to nearest, round up, round down, and round to zero. Microsoft SQL Server uses round up. All are accurate to the guaranteed precision but can result in slightly different floating-point values. Because the binary representation of a floating-point number may use one of many legal rounding schemes, it is impossible to reliably quantify a floating-point value
https://technet.microsoft.com/en-us/library/ms187912(v=sql.105).aspx

گروه تخصصی Sql Server


کلا در sql نوع های عددی رو به دو دسته تقسیم می کنیم دسته اول که بهشون approximate data types میگیم مانند float و real
به این معنا که عددی که شما قصد ذخیره اون در فیلدی با ابن نوع رو دارین، به صورت دقیق ذخیره نمیشه و یه تخمین بسیار نزدیک به اون ذخیره می شود
و اما سایر نوع های داده ای عددی integer, decimal, money, وsmallmoney و ... بر خلاف نوع داده ای float - real دقیقا مقدار عددی وارد شده رو ذخیره می کنند.

کاربرد Decimal - Numeric , ... :
1-زمانی که شما نیاز به انجام محاسبات دقیق دارید. برنامه های حسابداری - مالی - انبار و ...
2-استفاده از این ستون در شرط Where و عملگرهای = and <>

کاربرد نوع داده ای Float - Real:
دقت کنید زمانی که نیاز به نگهداری مقادیر اعشاری در یک جدول باشد دو مفهوم مطرح می شود:
Precision: تعداد کل ارقامی که یک نوع داده ای نگهداری می کند
Scale: تعداد ارقامی که در سمت راست (ارقام صحیح) قرار میگیرند

دو نوع داده ای numeric , decimal مقدار Precision برابر با 38 می باشد. بنابراین اگر نیاز به نگهداری مقادیری در جدولتون دارین که تعداد ارقام اون از 38 بیشتر باشد این نوع های داده ای مناسب هستند.

نتیجه گیری:
از نوع داده ای decimal و numeric زمانی که دقیق بودن اعداد و محاسبات برای شما مهم و حیاتی هستند استفاده کنید
از نوع های داده ای Flat ,Real در مقایسه ها (= و < و >) در شرط where استفاده نکنید
۹۷/۰۱/۲۳ موافقین ۰ مخالفین ۰

نظرات  (۰)

هیچ نظری هنوز ثبت نشده است

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی