For the complete documentation index, see llms.txt. This page is also available as Markdown.

Math Tags Null Value Error: Ending Position Out of Bounds (22) Stack Invalid Double

This error usually means a field inside a <MATH> tag is blank.

S-Docs expects a number.

If a merge field returns null instead, the calculation can fail with errors like:

  • Ending position out of bounds: 22 STACK

  • Invalid double

Fix 1: Replace blank values with 0

This is the fastest fix.

Add replaceall=" ,0" to any numeric field that might be blank.

null-safe-math.xml
<MATH>
  {{!Opportunity.Amount replaceall=" ,0"}} +
  {{!Opportunity.CustomField__c replaceall=" ,0"}}
</MATH>

Use this pattern when:

  • the field is numeric

  • blank values should behave like zero

  • you want the calculation to always run

Fix 2: Only run math when data exists

Use a named query and conditional logic when a missing value means the calculation should not run at all.

This pattern first checks whether matching records exist.

Then it runs the calculation only when there is data to use.

Use this pattern when:

  • the calculation depends on query results

  • zero would be misleading

  • you only want output when records exist

This issue is commonly tied to the Invalid double error. If you see both messages, check for blank numeric fields first.

Quick checklist

Before you test again, confirm these items:

  • every field inside <MATH> returns a number

  • blank numeric fields use replaceall=" ,0" when needed

  • query-based math is wrapped in RENDER when results may be missing

  • your <MATH> tag opens and closes correctly

Next step

For a beginner walkthrough, see Get Started with Calculations.

Last updated

Was this helpful?