适用范围: NoSQL
将数值表达式的值舍为指定箱大小的倍数。
语法
NumberBin(<numeric_expr> [, <bin_size>])
参数
| 描述 | |
|---|---|
numeric_expr | 
一个数值表达式,它会进行求值,然后将结果值舍入为指定箱大小的倍数。 | 
bin_size(可选) | 
一个数值,它指定在舍入值时要使用的箱大小。 如果没有指定,则此数值默认为 1。 | 
返回类型
返回数值。
示例
第一个示例用各种不同的箱大小对一个静态数字进行装箱。
SELECT VALUE {
    roundToNegativeHundreds: NumberBin(37.752, -100),
    roundToTens: NumberBin(37.752, 10),
    roundToOnes: NumberBin(37.752, 1),
    roundToZeroes: NumberBin(37.752, 0),
    roundToOneTenths: NumberBin(37.752, 0.1),
    roundToOneHundreds: NumberBin(37.752, 0.01)
}
[
  {
    "roundToNegativeHundreds": 100,
    "roundToTens": 30,
    "roundToOnes": 37,
    "roundToOneTenths": 37.7,
    "roundToOneHundreds": 37.75
  }
]
下一个示例使用现有项目中的字段。
{
  "name": "Ignis Cooking System",
  "price": 155.23478
}
此查询使用该函数对前一个字段进行舍入。
SELECT
    p.name,
    NumberBin(p.price, 0.01) AS price
FROM
    products p
WHERE
    p.category = "portable-cooking"
[
  {
    "name": "Ignis Cooking System",
    "price": 155.23
  }
]
注解
- 如果指定的箱大小为 
0,则此函数返回undefined。 - 默认箱大小为 
1。 此箱大小有效地返回了舍入到下一个整数的数值。