IntegerFormatter

class IntegerFormatter(format: String)

Backend for formatting integers by string pattern.

Format description: +0(number)b|B|x|X

  • + - forces to proceed the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a minus sign.

  • 0 - left-pads the number with zeroes (0) instead of spaces when padding is specified.

  • number - minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.

  • b|B - binary representation.

  • x - hexadecimal representation.

  • X - hexadecimal representation (uppercase).

Examples:

  • format="+05", number=3 => "+0003"

  • format="+5", number=3 => " +3"

  • format="x", number=255 => "ff"

  • format="04X", number=255 => "00FF"

Author

Alexander Kornilov (akornilov.82@gmail.com).

Parameters

format

pattern for formatting (see details above).

Throws

Constructors

IntegerFormatter
Link copied to clipboard
fun IntegerFormatter(format: String)
pattern for formatting (see details above).

Functions

format
Link copied to clipboard
inline fun <T : Any> format(negative: Boolean, initValue: T, getDigit: (radix: Int, T) -> Pair<T, Int>?): String
Formats digits according settings: sign, pad, padZero, radix and capital.

Properties

capital
Link copied to clipboard
val capital: Boolean
Indicates that digits of the number which represented as a letter (e.g.
pad
Link copied to clipboard
val pad: Int
Minimum number of characters to be printed.
padZero
Link copied to clipboard
val padZero: Boolean
Indicates that pad should be zeros.
radix
Link copied to clipboard
val radix: Int
The radix of the number representation.
sign
Link copied to clipboard
val sign: Boolean
Indicates that sign should be displayed even for positive numbers.