toDouble
Converts this value to a BsonType.Double.
Conversion algorithm
BsonType.Double is returned as itself.
BsonType.Int32 and BsonType.Int64 are extended to a double.
BsonType.Boolean becomes 1 if true
and 0 if false
.
BsonType.Decimal128 is converted if it is within the possible range of a double value. Otherwise, an exception is thrown.
BsonType.String is parsed as a double. Only base 10 numbers can be parsed. If the value is outside the range of a double, an exception is thrown. "-5.5"
and "123456"
are two valid examples.
BsonType.Datetime returns the number of milliseconds since the epoch.
BsonType.Null always returns null
.
Other types throw an exception.
Example
class Metric(
val instant: Instant,
val millis: Double
)
users.aggregate()
.set {
User::millis set of(Metric::instant).toDouble()
}
Content copied to clipboard
External resources
See also
Get the value's type.