<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a5a1e3ce-00fa-46e4-9a75-58c2aed9e8ce/Notion_Fundamentals_with_Thomas_Frank_-_Avatar_2021.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a5a1e3ce-00fa-46e4-9a75-58c2aed9e8ce/Notion_Fundamentals_with_Thomas_Frank_-_Avatar_2021.png" width="40px" /> Stores often ask customers if they would like to make a donation to charity along with their purchase.

This example database calculates donations based on four possible options - $1, $5, Round-Up, and no donation.

A “round-up” donation simply rounds the purchase sub-total to the next greatest whole dollar, and donates the change.

Created by Thomas Frank | Learn Notion Formulas | Notion Basics | Templates | Twitter

</aside>

Round-Up Donations

// Compressed
if(contains(prop("Donation Choice"),"$"),toNumber(replaceAll(prop("Donation Choice"),"[^\\\\d]","")),if(prop("Donation Choice") == "Round-Up",ceil(prop("Subtotal")) - prop("Subtotal"),0))

// Expanded
if(
    contains(
        prop("Donation Choice"),
        "$"
    ),
    toNumber(
        replaceAll(
            prop("Donation Choice"),
            "[^\\\\d]",
            ""
        )
    ),
    if(
        prop("Donation Choice") == "Round-Up",
        ceil(prop("Subtotal")) - prop("Subtotal"),
        0
    )
)

Here is the piece of the above formula that utilizes ceil(), isolated:

ceil(prop("Subtotal")) - prop("Subtotal")

© Thomas Frank