Otera.Format (otera v0.1.0)

Copy Markdown View Source

Python string formatting: the % operator, which the format filter of Jinja2 uses, and str.format().

Both support the conversions and the format specification that templates use: fill, alignment, sign, width, precision, and the types s, r, d, i, f, e, g, x, o, b, c and %.

Summary

Functions

Formats a non-negative float with decimals digits after the point, like Python "%.<decimals>f". A negative decimals rounds to tens, hundreds and so on.

Formats args and kwargs into format with the rules of Python str.format().

Formats args into format with the rules of the Python % operator.

Functions

fixed(value, decimals)

@spec fixed(float(), integer()) :: String.t()

Formats a non-negative float with decimals digits after the point, like Python "%.<decimals>f". A negative decimals rounds to tens, hundreds and so on.

The digits come from the exact value of the float, rounded half to even, as in Python.

format(format, args, kwargs)

@spec format(String.t(), list(), Otera.Dict.t()) :: String.t()

Formats args and kwargs into format with the rules of Python str.format().

printf(format, args)

@spec printf(String.t(), term()) :: String.t()

Formats args into format with the rules of the Python % operator.