如何在 Postgres SQL 中获取双精度数中的 1 位整数?

How to get 1 digit interger number in a double number in Postgres SQL?

在 Postgres 中 SQL:

是否可以从双数中得到一位数?

例如:

我有 27/10 = 2.7

我只想获取数字“2”(作为数字而非字符串)

我试图将 2.7 转换为整数,但它会四舍五入为 3。

如何获取2.7中的数字2作为数字

感谢大家的回答。

--------已编辑------------

我找到了 floor() 来做到这一点。

我的成功结果是“SELECT FLOOR(column_name/10) as A FROM table_name

我将数字 2.7 更改为 column_name/10(column_name 是包含双精度类型数据的列)

希望对大家有所帮助。

trunc 函数会将数字截断为给定的小数位数:

select trunc(2.7, 0);
 trunc
-------
     2
(1 row)

27/10 将给出 2 没有任何功能的结果。

 select  27/10::numeric  
        ,27/10::real
        , 27/10 as the_result_you_need