Numeric Helpers API reference for numeric template helpers hash API Reference
Categories

Numeric Helpers

Numeric helpers provide utilities for working with numbers in templates.

Functions

numberFromIndex

Returns the index plus one, useful for human-readable numbering.

Template Syntax

{numberFromIndex index}

Parameters

NameTypeDescription
anumberThe index value

Returns

number - The index plus one.

Example

{#each items}
Item {numberFromIndex index}: {this}
{/each}

maybePlural

Adds a plural suffix if the value is not 1.

Template Syntax

{maybePlural itemCount 's'}

Parameters

NameTypeDefaultDescription
valuenumberThe count to check
pluralstring’s’The plural suffix to add

Returns

string - The plural suffix if the value is not 1, otherwise an empty string.

Example

<p>You have {itemCount} item{maybePlural itemCount} in your cart.</p>

roundNumber

Rounds a number to a specified number of decimal places.

Template Syntax

{roundNumber numberToRound precision}

Parameters

NameTypeDescription
numbernumberThe number to round
precisionnumberNumber of decimal places

Returns

number - The rounded number.

Example

<p>Average score: {roundNumber score 1}</p>
<p>Price: ${roundNumber price 2}</p>

round

Alias for roundNumber. Rounds a number to a specified number of decimal places.

Template Syntax

{round numberToRound precision}

Parameters

NameTypeDescription
numbernumberThe number to round
precisionnumberNumber of decimal places

Returns

number - The rounded number.

Example

<p>Temperature: {round temperature 1}°C</p>

roundDecimal

Rounds a number to a specified number of decimal places using decimal rounding.

Template Syntax

{roundDecimal numberToRound precision}

Parameters

NameTypeDescription
numbernumberThe number to round
precisionnumberNumber of decimal places

Returns

number - The rounded number using decimal rounding.

Example

<p>Precise measurement: {roundDecimal measurement 3}mm</p>
Previous
Logical Operators
Next
Objects