Convert text to a number in a NetSuite saved search

Use Formula Numeric with TO_NUMBER, verify text conversion before arithmetic, then calculate amount per package with explicit zero handling.

The quick answer

Use Formula (Numeric) with TO_NUMBER({custbody_package_count_text}) when that text field contains valid numeric strings. Test the conversion first. Then repeat it inside the calculation:

{amount}/NULLIF(TO_NUMBER({custbody_package_count_text}),0)

TO_NUM is the wrong function name. The input field being text does not require Formula (Text); choose the result type that matches the expression's output. NULLIF guards a converted zero denominator. It does not make arbitrary text numeric.

Before you start

You need permission to edit the Transaction saved search and view its source transactions. Field availability and labels vary with role and account configuration.

This example uses an existing search named Amount per Package Review, with Type = Sales Order and Main Line = Yes. Its custom Package Count Text field is Free-Form Text with example ID custbody_package_count_text. Replace that ID with your own field's ID.

These five illustrative test rows have amount 120. Their package counts are plain text 1, 2, 6, 0 and blank. With Main Line = Yes, the amount is at the transaction/header level, so this is one ratio per sales order, with no summary grouping. This guide keeps Formula (Numeric) for a numeric result without a currency symbol; use Formula (Currency) when monetary formatting is required. Check that the amount field and currency match your reporting purpose.

01. Inspect the function name

Open Results > Columns, select the existing Formula (Numeric) row and open its formula popup. The starting expression uses TO_NUM({custbody_package_count_text}). Correct the function name before testing arithmetic.

TO_NUM is the function name to correct.

02. Test conversion alone

Replace the expression with:

TO_NUMBER({custbody_package_count_text})

Click Set, then OK to commit the row. Keep Formula (Numeric), leave Summary Type blank, and keep the custom label Numeric Package Count for this check.

Test the conversion alone before adding arithmetic.

Preview the search. Compare Package Count Text with Numeric Package Count. Text values 1, 2, 6 and 0 produce numbers 1, 2, 6 and 0; the null or empty test value stays blank. Enlarge the screenshot to compare all original text values. If this step fails, check the field ID and actual stored values before adding division.

The conversion test keeps zero as zero and the empty input blank.

03. Expand the formula

Return to the criteria, reopen Results, select the formula row and open its popup. Replace the conversion test with:

{amount}/NULLIF(TO_NUMBER({custbody_package_count_text}),0)

Repeat TO_NUMBER inline. Numeric Package Count is a result label, not a field ID another formula can reference. Click Set, change Custom Label to Amount per Package, then click OK.

Repeat TO_NUMBER inside the denominator; NULLIF guards a converted zero.

04. Save and verify ratios

Save the existing search. In these illustrative test rows, with amount 120, counts 1, 2 and 6 produce 120, 60 and 20. The zero and blank counts produce blank ratios. Confirm all five transactions and their original text values remain visible.

Amount 120 divided by counts 1, 2, 6 gives 120, 60, 20; zero and blank give blank ratios.

Conversion changes the search result, not the custom field's type or stored text. Keep invalid text out of this field or validate it separately. NULLIF protects against zero after conversion; a value such as boxes can still cause a conversion error.

Common questions

Should TO_NUMBER use Formula (Numeric) or Formula (Text)?

Use Formula (Numeric) when the expression returns a number for calculation. The source field can be text. Formula (Text) is for a text result or formatting, not a requirement imposed by a text input.

Can one formula refer to another result column's label?

A saved-search result label does not create a reusable formula variable. Repeat the expression with the underlying field IDs inside the next calculation.

Does NULLIF handle invalid text?

No. NULLIF compares the converted value with zero. TO_NUMBER still has to convert the original text, so nonnumeric text can fail before that comparison.

Why are some ratios blank?

A null or empty text value normally gives a null conversion and has no usable denominator. Whitespace and other visually blank text still need validation. A converted zero becomes null through NULLIF. Both yield a blank ratio. A blank ratio means the calculation is undefined; it is not a measured zero. A genuine zero amount divided by a valid nonzero count remains numeric zero.

What about commas, decimal separators or units?

This example uses plain digits. Values with grouping separators, decimal conventions or unit labels need validation and, when appropriate, an explicit supported format model. Do not assume every formatted string converts under the account's number conventions.