整数的科学记数法 [英] Scientific notation to whole numbers
问题描述
我正在使用 XQuery 中的一些数学函数推断未来 10 年的人口增长,如下所示:
I'm extrapolating population growths 10 years in the future using some math functions in XQuery, like so:
let $db := doc("mondial.xml")
for $country in $db/mondial/country
let $last_pop := $country/population[last()]
let $snd_last_pop := $country/population[last() - 1]
let $pop_growth := $last_pop div $snd_last_pop
let $yt2026 := 2026 - $last_pop/@year
return <country>
{$country/name}
<population year="2026" measured="extrap.">{
$last_pop * math:exp($yt2026 * math:log($pop_growth))
}</population>
</country>
但是,我的输出要么是科学记数法,要么有很多小数位.
However, my output is either in scientific notation, or has a lot of decimal places.
<country>
<name>Albania</name>
<population year="2026" measured="extrap.">706860.8616776819</population>
</country>
<country>
<name>Greece</name>
<population year="2026" measured="extrap.">9.19404785580711E6</population>
</country>
<country>
<name>Macedonia</name>
[...]
使用 xs:int()
会产生错误.
如何以整数显示这些值?(这个符号的名称是什么?'普通符号'?)
How do I show these values in whole numbers? (And what is the name of this notation? 'Normal notation'?)
推荐答案
您可以使用 format-number(9.19404785580711E6, "0")
强制执行没有小数位数的非科学输出.该值在返回之前四舍五入,因此给定语句的结果将是 9194048
.
You can enforce non-scientific output without fractional digits using format-number(9.19404785580711E6, "0")
. The value is rounded before being returned, such that the result for the given statement would be 9194048
.
这篇关于整数的科学记数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!