Skip to content

Integer Functions ​

abs ​

ts
int.abs(): integer

Returns the absolute value of an integer. If the integer is negative, it will return the positive value of it.

Input Example: ​

textwire
{{ (-5).abs() }}

Output: ​

html
5

decimal ​

ts
int.decimal(separator?: string = ".", decimals?: integer = 2): string

Ensures a numeric value has at least the requested number of decimal places. It pads shorter values with zeroes and leaves values that already have enough decimal places unchanged. It does not round or remove extra decimal places.

  • Integers are padded with zeroes: 123.decimal() returns string "123.00"
  • Numeric strings that already have enough decimal places are returned unchanged: "123.456".decimal() returns string "123.456"
  • Numeric strings with fewer decimal places are padded: "123.4".decimal() returns string "123.40"
  • Strings that are not numbers are returned unchanged

decimals defaults to 2. Negative values are treated as 0.

Arguments: ​

  1. separator (str) (optional) - The separator to use for the decimal. Default is "."
  2. decimals (int) (optional) - How many decimal places to ensure. Default is 2. Negative values are treated as 0

Input Example: ​

textwire
{{ 123.decimal() }}
{{ 123.decimal(".", 0) }}
{{ 123.decimal(".", -1) }}

Output: ​

html
123.00
123
123

float ​

ts
int.float(): float

Converts an integer to a float by adding a decimal part of .0 to the number.

Input Example: ​

textwire
{{ 5.float() }}

Output: ​

html
5.0

The value 0 will be converted to 0.0.

len ​

ts
int.len(): integer

Returns the number of digits in an integer. If the integer is negative, it will return the number of digits excluding the - sign.

Input Example: ​

textwire
{{ 12345.len() }}

Output: ​

html
5

str ​

ts
int.str(): string

Converts an integer to a string and returns it.

Input Example: ​

textwire
{{ 5.str() }} and {{ (-10).str() }}

Output: ​

html
5 and -10