TPLix

No results for ""

String Format

2 min read Jun 2, 2026
--- title: string_format autoseo: enabled: true theme: learn2 child_type: default admin: children_display_order: collection visible: true ---

string_format — This is a way to format strings, such as decimal numbers and such. Use the syntax for sprintf() for the formatting.

Basic Usage:
{$myVar|string_format:"%d"}
Parameters:
Parameter Type Required Description
1 string Yes This is what format to use. (sprintf)

Examples:

<?php
$tplix->assign('number', 23.5787446);

Where the template is:

{$number}
{$number|string_format:"%.2f"}
{$number|string_format:"%d"}

Output:

23.5787446
23.58
23

Leave a Comment

Not published. Used to notify you on approval.

Comments are moderated before appearing.