問題描述
我目前正在 MSDN 并遇到過以下短語.
I'm currently learning "numeric" data type on MSDN and have encountered the following phrase.
從十進制或數字轉換為浮點數或實數會導致一些精度損失.從 int、smallint、tinyint、float 轉換,real、money 或 smallmoney 轉換為十進制或數字可能會導致溢出.
Converting from decimal or numeric to float or real can cause some loss of precision. Converting from int, smallint, tinyint, float, real, money, or smallmoney to either decimal or numeric can cause overflow.
我真的不明白轉換十進制或數字"數據類型時精度損失/溢出背后的原因.有人可以給我解釋一下嗎?
I dont really understand the reason behind loss of precision/overflow when converting "decimal or numeric" data type. Could someone please explain it to me?
推薦答案
Decimal 或 Numeric 數據類型實際上是帶有小數分隔符位置的整數.關于聲明的精度,它們可以存儲最小值和最大值之間的每個值.正如 Ryan 所說,您可以在從 -32k 到 32k 的四個字節內存儲大約 64k 個不同的值.如果你創建一個四字節的浮點類型,范圍會更廣,但仍然有 64k 不同的值要存儲.范圍內的某些值無法精確存儲.
Decimal or Numeric data types are in fact integer with decimal separator position. They can store each value between min and max values, regarding declared precision. As Ryan said, you can store approx 64k different values within four bytes ranging from -32k to 32k. If you make a four bytes float type, the range would be much wider, but there are still 64k different values to be stored. Some of the values within the range are impossible to be stored precisely.
這篇關于轉換“十進制或數字"時精度丟失/溢出的原因;數據類型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!