Files
smarty/docs/designers/language-modifiers/language-modifier-string-format.md

44 lines
770 B
Markdown
Raw Permalink Normal View History

2023-02-06 14:42:31 +01:00
# string_format
This is a way to format strings, such as decimal numbers and such. Use
2023-02-03 22:31:59 +01:00
the syntax for [`sprintf()`](https://www.php.net/sprintf) for the
formatting.
2023-02-06 14:42:31 +01:00
## Basic usage
```smarty
{$myVar|string_format:"%d"}
```
2023-02-06 14:42:31 +01:00
## Parameters
2023-02-06 14:42:31 +01:00
| Parameter Position | Type | Required | Description |
|--------------------|--------|----------|---------------------------------------|
| 1 | string | Yes | This is what format to use. (sprintf) |
2023-02-06 14:42:31 +01:00
## Examples
2023-02-06 14:42:31 +01:00
```php
<?php
2023-02-06 14:42:31 +01:00
$smarty->assign('number', 23.5787446);
2023-02-06 14:42:31 +01:00
```
2023-02-06 14:42:31 +01:00
Where template is:
2023-02-06 14:42:31 +01:00
```smarty
{$number}
{$number|string_format:"%.2f"}
{$number|string_format:"%d"}
```
Will output:
2023-02-06 14:42:31 +01:00
```
23.5787446
23.58
23
```
2023-02-06 14:42:31 +01:00
See also [`date_format`](language-modifier-date-format.md).