将Postgre中一列中的数字四舍五入到最接近的整数


Rounding the numbers in a column in Postgre to the nearest whole number

您好。

我有多张表格,里面都是关于国家的信息。其中一个表格载有每个国家的人口数字;另一个包含每种语言的使用者百分比。

我们要取这两个数字,列一列每种语言的说话者人数。。。基本上,我们把它们相乘。这很简单。然而,不简单的是,以我们应该的方式展示它们

这是我正在使用的查询:

SELECT country.name AS '"country'", 
       city.name AS '"capital'", 
       country_language.language, 
       (country.population * country_language.percentage) AS '"speakers'" 
FROM lab2.country, lab2.country_language, lab2.city 
WHERE country.country_code = country_language.country_code 
AND city.id = country.capital 
AND country_language.is_official = true
ORDER BY country.name, 
        (country_language.percentage * country.population) DESC;

这就是第一个生成的表格单元格所填充的内容:

 1190528034.66797

它应该是:

 11905280

通常情况下,我只需要把这些整数做成一种或另一种味道,这样就能解决问题。但正如你所看到的,我想四舍五入的数字不一定出现在小数点之后。

我该怎么做才能把这些四舍五入?

这是我的网站(你想选择的是查询5):

http://babbage.cs.missouri.edu/~asm3kf/cs3380/lab2/lab2.php

这是我们应该匹配的页面:

http://babbage.cs.missouri.edu/~klaricm/cs3380/lab2/lab2.php

你会发现,这种不一致贯穿了整个表格。

提前感谢!

编辑:

我更新了网站,包括人口和百分比数字。希望这在某种程度上有所帮助。

是否将等式结果四舍五入?

round(country.population * country_language.percentage) AS '"speakers'"

添加所需的更改以适应百分比格式:

round(country.population * (country_language.percentage / 100)) AS '"speakers'"

除法可能会为您截断/舍入结果,无论如何,我手头没有PostgreSQL可供测试。