問題描述
我目前正在 MSDN 并遇到過以下短語(yǔ).
I'm currently learning "numeric" data type on MSDN and have encountered the following phrase.
從十進(jìn)制或數(shù)字轉(zhuǎn)換為浮點(diǎn)數(shù)或?qū)崝?shù)會(huì)導(dǎo)致一些精度損失.從 int、smallint、tinyint、float 轉(zhuǎn)換,real、money 或 smallmoney 轉(zhuǎn)換為十進(jìn)制或數(shù)字可能會(huì)導(dǎo)致溢出.
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.
我真的不明白轉(zhuǎn)換十進(jìn)制或數(shù)字"數(shù)據(jù)類型時(shí)精度損失/溢出背后的原因.有人可以給我解釋一下嗎?
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 數(shù)據(jù)類型實(shí)際上是帶有小數(shù)分隔符位置的整數(shù).關(guān)于聲明的精度,它們可以存儲(chǔ)最小值和最大值之間的每個(gè)值.正如 Ryan 所說(shuō),您可以在從 -32k 到 32k 的四個(gè)字節(jié)內(nèi)存儲(chǔ)大約 64k 個(gè)不同的值.如果你創(chuàng)建一個(gè)四字節(jié)的浮點(diǎn)類型,范圍會(huì)更廣,但仍然有 64k 不同的值要存儲(chǔ).范圍內(nèi)的某些值無(wú)法精確存儲(chǔ).
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.
這篇關(guān)于轉(zhuǎn)換“十進(jìn)制或數(shù)字"時(shí)精度丟失/溢出的原因;數(shù)據(jù)類型的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!