要将一个简单的数字存储到99.99,最好的数据类型是什么

时间:2022-02-02 06:40:42

I see there's a variety of different datatypes but I just want something small and simple that will store a number up to 99.999 and the last digit does not even have to be accurate? Can someone tell me which would be the most suitable and smallest datatype that I could use for this?

我看到有很多不同的数据类型,但我只是想要一个小而简单的数据,可以存储一个数字到99。999最后一个数字甚至不需要精确?谁能告诉我哪一种数据类型最适合和最小?

2 个解决方案

#1


1  

Try DECIMAL(4,2) which would allow you to store -99.99 to 99.99

试试DECIMAL(4,2),它可以让你存储-99.99到99.99

  • The 4 represents the precision which is the total number of digits that can be stored (to the left and right of the decimal place).
  • 4表示可以存储的数字总数(小数点左边和右边)的精度。
  • The 2 represents the scale which is the number of digits that can appear after the decimal place.
  • 2表示小数位数后面的位数。

#2


3  

float(24) would be the best one for your scenario. It will consume 4 bytes which is lower than Decimal/Numeric datatype with lowest precision(5 bytes).

float(24)是最适合您的场景的。它将消耗4个字节,低于精度最低的十进制/数字数据类型(5字节)。

MSDN - float

MSDN——浮动

MSDN - decimal/numeric

MSDN -十进制/数字

#1


1  

Try DECIMAL(4,2) which would allow you to store -99.99 to 99.99

试试DECIMAL(4,2),它可以让你存储-99.99到99.99

  • The 4 represents the precision which is the total number of digits that can be stored (to the left and right of the decimal place).
  • 4表示可以存储的数字总数(小数点左边和右边)的精度。
  • The 2 represents the scale which is the number of digits that can appear after the decimal place.
  • 2表示小数位数后面的位数。

#2


3  

float(24) would be the best one for your scenario. It will consume 4 bytes which is lower than Decimal/Numeric datatype with lowest precision(5 bytes).

float(24)是最适合您的场景的。它将消耗4个字节,低于精度最低的十进制/数字数据类型(5字节)。

MSDN - float

MSDN——浮动

MSDN - decimal/numeric

MSDN -十进制/数字