Skip to main content

$toNumber

The $toNumber operator converts a value to a number.

Input

  • A single value of any type

Output

  • The numeric representation of the input value

Examples

Convert String to Number

{
  "$toNumber": [
    "123"
  ]
}
Result: 123

Convert Boolean to Number

{
  "$toNumber": [
    true
  ]
}
Result: 1

Convert String with Decimal to Number

{
  "$toNumber": [
    "45.67"
  ]
}
Result: 45.67

From Field

{
  "$toNumber": [
    {
      "$input": "value"
    }
  ]
}
Result: The numeric representation of the value field