pnz/twig-extension-number 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pnz/twig-extension-number

最新稳定版本:2.0.0

Composer 安装命令:

composer require pnz/twig-extension-number

包简介

A Twig extension for number formatting

关键字:

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality

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

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

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']

统计信息

  • 总下载量: 53.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-10