si

Summary

Handles unit display of values (output formatting).

Usage

$input_value|si( unit [, prefix ] [, decimals ] [, decimal_symbol ] [, thousands_separator ] )

Parameters

NameTypeDescriptionRequired
unit string Unit to format input_value to yes
prefix string Prefix used to represent input_value no
decimals integer Number of decimal digits no
decimal_symbol string The symbol to use as decimal separator no
thousands_separator string The separator to place inbetween thousands no

Returns

input_value formated to specified si unit.

Description

Handles unit display of values, most often used for showing sizes of files but can also be used for displaying units on other items such as meters, grams etc.
The operator reads five parameters. The first tells the kind of unit type we're dealing with, for instance: byte, length.
The second determines the behavior of prefixes and is optional.
The third, fourth and fifth determines how to format the number and are option, if not supplied the values will be fetched from the current locale. (Exponential 3.3 or lower does not have these parameters nor this it use locale settings.)

Available units are

  • meter
  • gram
  • second
  • ampere
  • kelvin
  • mole
  • candela
  • byte
  • bit

You can add custom units by adding to the Base group in units.ini

The prefix is either the name of the size like kilo or one of these

  • binary - Calculate using 2 as base, e.g. 2^8
  • decimal - Calculate using 10 as base, e.g. 10^6
  • none - Show value as it is with just the unit appended
  • auto - Determine base from the type of unit, the setting BinaryUnits controls this (default is bit and byte)

Proper binary prefixes

  • kibi - 2^10 Ki
  • mebi - 2^20 Mi
  • gibi - 2^30 Gi
  • tebi - 2^40 Ti
  • pebi - 2^50 Pi
  • exbi - 2^60 Ei

Commonly used binary prefixes, should not be used if you want to be accurate

  • kilo - 2^10 k
  • mega - 2^20 M
  • giga - 2^30 G
  • tera - 2^40 T
  • peta - 2^50 P
  • exa - 2^60 E

Decimal prefixes

  • yotta - 10^24 Y
  • zetta - 10^21 Z
  • exa - 10^18 E
  • peta - 10^15 P
  • tera - 10^12 T
  • giga - 10^9 G
  • mega - 10^6 M
  • kilo - 10^3 k
  • hecto - 10^2 h
  • deca - 10^1 da
  • deci - 10^-1 d
  • centi - 10^-2 c
  • milli - 10^-3 m
  • micro - 10^-6 µ
  • nano - 10^-9 n
  • pico - 10^-12 p
  • femto - 10^-15 f
  • atto - 10^-18 a
  • zepto - 10^-21 z
  • yocto - 10^-24 y

All of these values are defined in the INI file units.ini

Examples

{1025|si(byte)}

{1025|si(byte,binary)}

{1025|si(byte,decimal)}

{1025|si(byte,none)}

{1025|si(byte,auto)}

{1025|si(byte,kibi)}

{1025|si(byte,kilo)}

If the setting UseSIUnits in site.ini is set to false (default value) then the output will be

1.00 kB

1.00 kB

1.02 kB

1025 B

1.00 kB

1.00 KiB

1.02 kB

If the setting UseSIUnits in site.ini is set to true then the output will be

1.00 KiB

1.00 KiB

1.02 kB

1025 B

1.00 KiB

1.00 KiB

1.02 kB

Comments

log in or create a user account to comment.

Contents

Reference

Database diagram
Template operators
    PDF
    Arrays
    Data extraction
    Formatting
       datetime
       i18n
       l10n
       si
       x18n
    Images
    Logic
    Mathematics
    Miscellaneous
    Strings
    URLs
    Variables
Template functions
Data fetching
Modules
XML tags


Created

05/02/2004
11:36:33 am
by Balazs Halasy

Last updated

04/05/2004
3:13:36 pm
by Jan Borsodi

Authors

Balazs Halasy
Kåre Køhler Høvik
Jan Borsodi



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.