在 PostgreSQL 中将分数格式化为一半或三分之一或四分之一
Fraction formatting as halves or one third or quarters in PostgreSQL
我在 PostgreSQL 的列中有一些双精度值,如下所示:
**amount**
*11.33
11.75
12.2
13.9
16.3
.....*
我想将这些值四舍五入到小数点后最接近的四分之一值。即:
11.333569 -> 11.50
11.7555698 -> 11.75
12.236558 -> 12.25
13.925669 -> 13.75
16.101235 -> 16.25
我在 MS Excel 中看到了这种功能。它可以在以下位置找到:
如何在 PostgreSQL 中执行相同的操作?在此先感谢您的帮助。
你可以使用算术:
select cast(round(x * 4) / 4.0 as decimal(10, 2))
Here 是一个 db<>fiddle.
我在 PostgreSQL 的列中有一些双精度值,如下所示:
**amount**
*11.33
11.75
12.2
13.9
16.3
.....*
我想将这些值四舍五入到小数点后最接近的四分之一值。即:
11.333569 -> 11.50
11.7555698 -> 11.75
12.236558 -> 12.25
13.925669 -> 13.75
16.101235 -> 16.25
我在 MS Excel 中看到了这种功能。它可以在以下位置找到:
如何在 PostgreSQL 中执行相同的操作?在此先感谢您的帮助。
你可以使用算术:
select cast(round(x * 4) / 4.0 as decimal(10, 2))
Here 是一个 db<>fiddle.