toNumber
Learn how to use the toNumber function in Notion formulas.
The `toNumber()` function converts its argument to a number if it can do so. It is useful for converting strings, Booleans, and dates to numbers.
1
toNumber(string)
2
toNumber(Boolean)
3
toNumber(date)
Unlike unaryPlus, `toNumber()` can convert dates to numbers. When used to convert a date, toNumber will convert it to its corresponding Unix timestamp; this behavior matches that of the timestamp function.
Good to know: If a string starts with a number and contains letter chracters as well,`toNumber()` will return just that starting number. However, if the string does not start with a number, `toNumber()` will output nothing – even if the string contains a number elsewhere.

# Example Formulas

1
toNumber("42") // Output: 42 (number)
2
3
toNumber("42 rabbits jump 100 times") // Output: 42
4
5
toNumber("I have 42 rabbits.") // Output: blank
6
7
toNumber(true) // Output: 1
8
9
toNumber(false) // Output: 0
10
11
toNumber(5>3) // Output: 1
12
13
toNumber(now()) // Output: 1655757000000 (changes with now()'s value)

# Example Database

This example database is a simple habit tracker. Each property represents a different habit, and the Habits formula property adds them up and outputs a string reporting the number of habits completed on that day.

## View and Duplicate Database

toNumber
College Info Geek on Notion

## “Habits” Property Formula

1
// Compressed
2
format(toNumber(prop("💧")) + toNumber(prop("🏃‍♂️")) + toNumber(prop("🏋️‍♀️")) + toNumber(prop("🥦"))) + "/4" + if((toNumber(prop("💧")) + toNumber(prop("🏃‍♂️")) + toNumber(prop("🏋️‍♀️")) + toNumber(prop("🥦"))) == 1," Habit"," Habits")
3
4
// Expanded
5
format(
6
toNumber(
7
prop("💧")
8
) +
9
toNumber(
10
prop("🏃‍♂️")
11
) +
12
toNumber(
13
prop("🏋️‍♀️")
14
) +
15
toNumber(
16
prop("🥦")
17
)
18
) +
19
"/4" +
20
if(
21
(
22
toNumber(
23
prop("💧")
24
) +
25
toNumber(
26
prop("🏃‍♂️")
27
) +
28
toNumber(
29
prop("🏋️‍♀️")
30
) +
31
toNumber(
32
prop("🥦")
33
)
34
) == 1,
35
" Habit",
36
" Habits"
37
)
This formula uses `toNumber()` to convert the Boolean output of each habit’s checkbox value into a number - either `1` or `0`. It then adds up all the numbers to get a total number of habits completed for the day.
The format function is then used to convert this number into a string so that it can be combined with the other string elements in the formula.
Finally, an if statement uses the same process to determine if the total number of habits completed is equal to `1`. If so, it outputs “Habit”; if not, it outputs the plural “Habits”.

### About the Author

My name is Thomas Frank, and I'm a Notion-certified writer, YouTuber, and template creator. I've been using Notion since 2018 to organize my personal life and to run my business and YouTube channel. In addition to this formula reference, I've created a free Notion course for beginners and several productivity-focused Notion templates. If you'd like to connect, follow me on Twitter.