Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql Postgres整数值未按公式更新_Postgresql - Fatal编程技术网

Postgresql Postgres整数值未按公式更新

Postgresql Postgres整数值未按公式更新,postgresql,Postgresql,我试图使用公式更改整型字段的值,但它从未设置正确的值: update "inventory" set "price" = round("cost" + ("cost" * (50 / 100)), 0) where "id" = 1 在这种情况下,cost=1000所以我希望price=1500但是我得到的是price=1000 我是不是错过了一些研究生的数学细节 PostgreSQL 9.6.1整数除法在欺骗你50/100=0。尝试50./100.,这给出了0.5的预期结果。细微差别确认。谢

我试图使用公式更改整型字段的值,但它从未设置正确的值:

update "inventory" set "price" = round("cost" + ("cost" * (50 / 100)), 0) where "id" = 1
在这种情况下,
cost=1000
所以我希望
price=1500
但是我得到的是
price=1000

我是不是错过了一些研究生的数学细节


PostgreSQL 9.6.1

整数除法在欺骗你<代码>50/100=0。尝试
50./100.
,这给出了0.5的预期结果。

细微差别确认。谢谢这不是一个真正的细微差别,更多的是关于预期的类型。在PostgreSQL中,当一个数字写为
100
时,假定为
integer
类型。要将
整数
强制为
浮点
,您需要执行类似
100::float
CAST(100作为浮点)
的操作。根据答案,
100.
可能是我在MySQL中遇到的不够的东西。通常,只要使用
round()
就足够了。无论如何,很高兴知道。