round

ReQL command: round

Command syntax

r.round(number) → number
number.round() → number

Description

Rounds the given value to the nearest whole integer.

For example, values of 1.0 up to but not including 1.5 will return 1.0, similar to floor; values of 1.5 up to 2.0 will return 2.0, similar to ceil.

Example: Round 12.345 to the nearest integer.

r.round(12.345).run(conn, callback);
// Result passed to callback
12.0

The round command can also be chained after an expression.

Example: Round -12.345 to the nearest integer.

r.expr(-12.345).round().run(conn, callback);
// Result passed to callback
-12.0

Example: Return Iron Man’s weight, rounded to the nearest integer.

r.table('superheroes').get('ironman')('weight').round().run(conn, callback);

Related commands

Get more help

Couldn't find what you were looking for?

© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/javascript/round/

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部