PHPackages                             pnz/twig-extension-number - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. pnz/twig-extension-number

ActiveLibrary[Localization &amp; i18n](/categories/localization)

pnz/twig-extension-number
=========================

A Twig extension for number formatting

2.0.0(5y ago)755.8k↓18.8%4[2 issues](https://github.com/thePanz/Twig-Extension-Number/issues)[1 PRs](https://github.com/thePanz/Twig-Extension-Number/pulls)MITPHPPHP &gt;=7.2.5

Since Mar 14Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/thePanz/Twig-Extension-Number)[ Packagist](https://packagist.org/packages/pnz/twig-extension-number)[ Docs](https://github.com/thePanz/Twig-Extension-Number)[ RSS](/packages/pnz-twig-extension-number/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (7)Used By (0)

Twig-Extension-Number
=====================

[](#twig-extension-number)

[![Latest Stable Version](https://camo.githubusercontent.com/4982eb3fbc368f7677a7e322ee223379e6cd478fc4f9d2b1e48adc50f5acb193/68747470733a2f2f706f7365722e707567782e6f72672f706e7a2f747769672d657874656e73696f6e2d6e756d6265722f762f737461626c652e737667)](https://packagist.org/packages/pnz/twig-extension-number)[![Total Downloads](https://camo.githubusercontent.com/1139f8f873b2fcf7019e1e79862b39e1c7b4808b4ea3a520c55ae77596854dcb/68747470733a2f2f706f7365722e707567782e6f72672f706e7a2f747769672d657874656e73696f6e2d6e756d6265722f646f776e6c6f6164732e737667)](https://packagist.org/packages/pnz/twig-extension-number)[![Latest Unstable Version](https://camo.githubusercontent.com/38f3e3e896799c79bf2de99f93a50485197b5f6e8842723491ebc091446a7f55/68747470733a2f2f706f7365722e707567782e6f72672f706e7a2f747769672d657874656e73696f6e2d6e756d6265722f762f756e737461626c652e737667)](https://packagist.org/packages/pnz/twig-extension-number)[![License](https://camo.githubusercontent.com/a218336473b2cc1a94d18b0d86c898495dcc63a7840230f110caa29689520de7/68747470733a2f2f706f7365722e707567782e6f72672f706e7a2f747769672d657874656e73696f6e2d6e756d6265722f6c6963656e73652e737667)](https://packagist.org/packages/pnz/twig-extension-number)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fbcd25f46f1459c5dd948ba8a4324219bf2793c59a3f36b99e0965164c5af2fa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74686550616e7a2f547769672d457874656e73696f6e2d4e756d6265722f6261646765732f7175616c6974792d73636f72652e706e673f623d322e78)](https://scrutinizer-ci.com/g/thePanz/Twig-Extension-Number/?branch=2.x)

A Twig extension to handle number formatting.

Included filters:

- `format_bytes` Formats the given amount as bytes and display it in an as a human-readable format. The filter supports 1000/1024 base counting and formatting
- `format_grams` Formats the given amount as "grams" in a human-readable format
- `format_meters` Formats the given amount as "meters" in a human-readable format

Examples
--------

[](#examples)

Display the value of 4000 grams in a human-readable format (4.00 Kg):

```
{{ 4000 | format_grams }}

```

The filter allows some customization of the output, given its signature `filter_grams(decimals, unityBias)`:

- *Decimals*: Display the value of 4000 grams in a human-readable format with 3 decimals (4.000 Kg): ```
    {{ 4000 | format_grams(3) }}

    ```
- *UnityBias*: Set the filter to handle the number as being expressed with a different bias then the standard unit (grams). To display the value of 4000 (expressed in milligrams, `1E-3`) as grams in a human-readable format with 3 decimals (4.00 g) use: ```
    {{ 4000 | format_grams(3, 1E-3) }}

    ```

Install
-------

[](#install)

Via composer:

```
    composer require "pnz/twig-extension-number"
```

In Symfony, tag `Pnz\TwigExtensionNumber\Number` with `twig.extension`, and the filter will be automatically registered.

```
    # file: config/services.yaml
    Pnz\TwigExtensionNumber\Number:
        tags: ['twig.extension']
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~357 days

Total

7

Last Release

1942d ago

Major Versions

1.1.0 → 2.0.0-rc12021-01-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a788c96bbcf89371ff0c614ad9f1655363369cb8e17ffd7afbebf046da6dad8?d=identicon)[thepanz](/maintainers/thepanz)

---

Top Contributors

[![thePanz](https://avatars.githubusercontent.com/u/226021?v=4)](https://github.com/thePanz "thePanz (30 commits)")[![bgatellier](https://avatars.githubusercontent.com/u/1890804?v=4)](https://github.com/bgatellier "bgatellier (1 commits)")[![h4cc](https://avatars.githubusercontent.com/u/2981491?v=4)](https://github.com/h4cc "h4cc (1 commits)")

---

Tags

i18nnumber

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pnz-twig-extension-number/health.svg)

```
[![Health](https://phpackages.com/badges/pnz-twig-extension-number/health.svg)](https://phpackages.com/packages/pnz-twig-extension-number)
```

###  Alternatives

[symfony/string

Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way

1.8k724.1M827](/packages/symfony-string)[symfony/intl

Provides access to the localization data of the ICU library

2.6k199.8M1.1k](/packages/symfony-intl)[jackocnr/intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers

8.2k243.6k2](/packages/jackocnr-intl-tel-input)[gettext/gettext

PHP gettext manager

70130.2M102](/packages/gettext-gettext)[jms/translation-bundle

Puts the Symfony Translation Component on steroids

42510.8M63](/packages/jms-translation-bundle)[sonata-project/intl-bundle

Symfony SonataIntlBundle

2159.0M48](/packages/sonata-project-intl-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
