计算机数学
precision vs scale
sql 中的 decimal 函数的签名如下:DECIMAL[(precision[,scale])]
DECIMAL with no precision or scale values is equivalent to DECIMAL(9,0).
precision represents the total number of digits that can be represented by the column, regardless of the location of the decimal point. This value must be between 1 and 38. For example, representing integer values up to 9999, and floating-point values up to 99.99, both require a precision of 4. You can also represent corresponding negative values, without any change in the precision. For example, the range -9999 to 9999 still only requires a precision of 4.
precision 表示总位数。
scale represents the number of fractional digits. This value must be less than or equal to precision. A scale of 0 produces integral values, with no fractional part. If precision and scale are equal, all the digits come after the decimal point, making all the values between 0 and 0.999… or 0 and -0.999…
scale 表示小数点后的位数。
在 sql 中转化字符串为数字的方式:select cast(recurr as decimal(19, 9))
同比环比
- 环比是由month-on-month翻译过来的
- 同比是由year-on-year翻译过来的
环比:是连续2个单位周期内的量的变化比。
同比:是一个单位周期内和另一个更大周期的同一个段周期内的变化比。环比只有一个,同比则因参照量(另一个更大周期)不同而不同,有多个。例如我今天(12.25日,星期日)步数是1000步,昨日800步,则环比为 1000/800=1.25;同比有多个,例如上周日为700步,上月25日900步,则上周同比为1000/700,上月同比为1000/900。有人遇到上月同比和上周同比时,把上周同比当成环比来理解了。记住一个重点,环比是连续(无任何时间间隔)周期内变化。
ceil vs floor
ceil 是 the smallest (closest to negative infinity) floating-point value that is greater than or equal to the argument and is equal to a mathematical integer。即向上取整。
floor 是 the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer. 即向下取整。
round 是四舍五入。