MENU
    Numbers and Numeric Precision
    • 29 Jan 2025
    • 6 読む分
    • 寄稿者

    Numbers and Numeric Precision


    The content is currently unavailable in Ja - 日本語. You are viewing the default English version.
    記事の要約

    Following Release 306, Tulip is changing the way numbers are stored in Tables and Completion Records to support capturing, storing, and displaying trailing zeros.

    The Number data type is a real number (i.e. 53, 700, 506.2, 7.645). Tulip’s numeric precision allows numbers to contain trailing zeros (i.e. 1.90, 7.300, 36.850, 419.38910).

    Details of Numeric Precision

    Number Input data saves trailing zeros
    Operator data entered through Number Inputs preserves trailing zeros on storage and display throughout the Tulip ecosystem - up to 20 digits after the decimal. Inputs over 20 digits will be rounded to the nearest 20th digit
    Table data stores in a new precise data type called Postgres Decimal - instead of floats.

    Table record data displays all digits after decimals
    Tables display all digits after the decimal with an ellipsis at column width. The previous UX limitation only showed the first 3 digits in the grid view. To view all digits past the decimal, click on the Table Record.

    Number inputs and expressions can control digits to desired decimals
    App Builders can specify and enforce digits on input and computation via:

    Number input validation for decimals

    • Expressions for managing decimal places of external inputs (i.e. Connectors, Devices, Machines, Custom Widgets) and performing mathematical computations. These expressions include ROUND() and GETDECIMALPLACES().
    • A new Expression, TOPLAINTEXT(), emits decimals with full precision.

    Read more about these expressions in the section below: Expressions to Manage Precision.

    Limits and Out-of-Bounds Behavior

    Maximum value: JS MAX SAFE INT

    • This is the standard maximum value for numeric data in Javascript
    • Tulip Tables API out of bounds handling: Incoming data larger than this will raise an error and not be stored.

    Maximum digits after the decimal: 20

    • This is more than the number of digits in floats (previously Tulip supported 15 digits), and encompasses all known use cases.
    • Tulip Tables API out of bounds handling: Incoming data with more than 20 digits will be rounded to the nearest 20th digit

    How does numeric precision work with other Tulip features?

    Input data with trailing zeros only applies to Number Inputs in Apps. Other data streams in Tulip handle numeric precision differently:

    External data

    Data coming in through Connectors, Machines, Devices, and Custom Widgets is still sent in as Strings or Floats, this is dependent on the data type provided by the source. Numeric data is converted to Postgres Decimals upon storage to Tulip Tables and Completion Records.

    Automations

    Automations will support trailing zeroes later in 2025. Currently, automations performing computations do not store trailing zeros.

    Expressions to Manage Precision

    App builders can manage digits when storing numbers in Tulip with the following expression.

    ROUND()

    Use ROUND() to specify the desired number of decimals and add trailing zeros before storing the value.

    App builders can manage digits when doing mathematical computations, including averages and sums, with the following expressions.

    GETDECIMALPLACES() and ROUND()

    Use GETDECIMALPLACES() and/or ROUND(), to manage decimal places for computation results.

    TOPLAINTEXT()

    Use TOPLAINTEXT() instead of TOTEXT() to see full decimal places of precision of a numeric value, including trailing zeros. This is because TOTEXT() retains a backward-compatible implementation to display precise decimals as Javascript Numbers (i.e. floats) with at most 16 digits of precision.

    Technical Details

    • As part of this release, Tulip Tables and Completions have moved from “floats” to precise Postgres Decimals, which are configured to store up to 20 digits after the decimal.
    • Incoming numeric data from all sources (i.e. Apps, Tulip Table API, Connectors, etc.) stores in Tulip Tables as Postgres Decimals and will round to a maximum of 20 digits upon storage.

    Historical Data

    Data collected prior to Release 306 has been completely preserved, keeping the numeric values the same. Any new incoming data is rounded to 20 digits after the decimal point.

    Minor Changes

    There are some edge case changes and caveats in how numbers are handled in apps after the Numbers Precision rollout, as a result of the differences between decimals and floats:

    1. Expressions: Javascript NaN & Infinity don’t exist in precise Decimal numbers — as a result, Expressions will now raise an error on mathematical error cases (ex. taking the square root of a negative number or dividing by 0).
      a. This means App Builders may have to update any special case logic that works with JS NaN and Infinity. These are not a supported interface, and we do not advise leveraging them to navigate mathematical edge cases in your apps.
    2. Triggers: Show Message now using quotes to wrap numbers
      a. This means you’ll now be able to display trailing zeros in Show Message.
    3. Tables: CSV exports now show full numbers (that are more than 1e6) – previously, the CSV used exponential notation for large numbers (greater than 1e6).
      a. This means your Admins may need to update CSV processing scripts to remove any special cases for processing exponentials, if they had them.
    4. Expressions: TOTEXT & number representation – If you need to preserve trailing zeros in textual representation, use a new expression TOPLAINTEXT() which wraps numbers in quotes to preserve trailing zeros.
      a. Expressions: TOTEXT() does not wrap numbers in quotes and therefore doesn’t preserve trailing zeros. Instead, use new TOPLAINTEXT() to view the full number with trailing zeros, wrapped in quotes.
      b. We’re introducing TOPLAINTEXT() as a new Expression to preserve backwards compatibility for apps that may have been using the TOTEXT() expression.

    If you have any questions about working with numbers precision, contact your CSM or post in the Community thread.


    この記事は役に立ちましたか?