Overview Examples Screenshots Comparisons Applications Download Documentation Tutorials Bazaar Status & Roadmap FAQ Authors & License Forums Funding Ultimate++
Search on this site

 Number formatting

String FormatIntBase(int i, int radix, int width = 0, char lpad = ' ', int sign = 0, bool upper = false)

Formats a signed or unsigned integer i in a given radix with left padding to given width with a given lpad character. If sign is +1 = always prepend '+'/-, if 0 = auto ('-' only), if -1, format as unsigned. If upper is true, letters for base > 10 are uppercase. If i is Null, returns empty String.

String FormatInt(int i)

Outputs decimally formatted signed integer i without + or any paddings. Supposed to be quite fast. Equivalent to FormatIntBase(i, 10).

String FormatIntDec(int i, int width, char lpad = ' ', bool always_sign = false)

Formats a signed decimal integer i with left padding up to given width characters (output longer than this is not padded) with a given lpad character. If always_sign is true, start positive numbers with '+' (negative numbers always start with '-').

String FormatIntHex(int i, int width = 8, char lpad = '0')

Formats an unsigned hexadecimal (radix 16) integer i with left padding up to given width characters (output longer than this is not padded) with a given lpad character.

String FormatIntOct(int i, int width = 12, char lpad = '0')

Formats an unsigned octal (radix 8) integer i with left padding up to given width characters (output longer than this is not padded) with a given lpad character.

String FormatIntRoman(int i, bool upper = false)

Formats a signed integer i in Roman numerals. The biggest "implemented" numeral is M (1000), so expect quite a long return string when formatting a billion. Negative numbers are prepended with [-], 0 or Null is output as a Null String. If upper is true, use uppercase [true] or lowercase [false] letters

String FormatIntAlpha(int i, bool upper = true)

Formats a signed integer i in length-first lexicographic index, i.e. excel column numbering (1 = A,2 = B..  26 = Z, 27 = AA, 28 = AB .. 52 = AZ, 53 = BA ... 78 = BZ etc). 0 or Null is output as a Null String. Only negative numbers are prepended with a [-]. If upper is true, use uppercase letter.

String Format64(uint64 a)

Formats an unsigned decimal 64-bit integer a. Supposed to be quite fast.

String Format64Hex(uint64 a)

Formats an unsigned hexadecimal a (radix 16) 64-bit integer. Supposed to be quite fast. Lowecase letters a-f are used for digits [10] through [15].

String FormatIntHex(const void *ptr)

Formats the pointer address ptr as a hexadecimal (base 16) number zero-padded to the number of digits appropriate for the memory model (8 digits in 32-bit systems, 16 digits in 64-bit systems). Useful for logging and debugging purposes. Equivalent to FormatHex, god knows why there are two of them.

String FormatHex(const void *ptr)

Same as FormatIntHex.

String FormatInteger(int a)

Formats a signed decimal integer without padding. In comparison to FormatInt it returns String(Null) when given int(Null) whereas FormatInt returns a plain empty string.

String FormatUnsigned(unsigned long a)

A very old freak, implemented through Sprintf("%u", a). Deprecated.

String FormatDouble(double a)

Formats a floating point a in decimal notation automatically selecting ordinary or scientific (exponential) notation according to the absolute value of a. In ordinary notation, the number is formatted to 10 significant digits; in exponential notation, the mantissa is formatted to 10 decimal digits.

String FormatBool(bool a)

Formats a boolean a as one of the fixed words "true" or "false" (regardless of language settings).

String FormatInt64(int64 a)

Formats a signed decimal 64-bit integer a without any padding. Only negative numbers are prepended with a [-].

String FormatDouble(double d, int digits, int flags = 0, int fill_exp = 0)

Formats a floating point number d in decimal notation automatically selecting ordinary or scientific (exponential) notation according to the absolute value of a and the given number of digits. In the (default) absolute decimal mode, a number is formatted in exponential notation whenever its absolute value exceeds the interval [1e-15, 1e+15]; in relative (significant) decimal mode (FD_REL), a number is formatted in exponential notation whenever its absolute value exceeds the interval [10^-<2 * digits>, 10^+<2 * digits>]. flags can be a binary combination (|) of

 FD_SIGN always prepend sign (+10) FD_REL relative decimal places (valid digits) FD_SIGN_EXP always prepend sign to exponent (1e+2) FD_CAP_E capital E for exponent (1E10) FD_ZERO keep trailing zeros (1.25000) FD_FIX always use fixed notation (FormatDouble only) FD_EXP always use exponential notation (FormatDouble only)

fill_exp is left zero-padding of exponent in exponential notation

String FormatDoubleFix(double d, int digits, int flags = 0)

Formats a floating point number d in ordinary decimal notation (whole part, comma, decimal part). Then number of digits can be interpreted either as the absolute number of decimal digits (the default mode) or the relative number of significant digits excluding leading zeros. Decimal point is always output as a period independent on language settings. flags can be a binary combination (|) of

 FD_SIGN always prepend sign (+10) FD_REL relative decimal places (valid digits) FD_ZERO keep trailing zeros (1.25000)

String FormatDoubleExp(double d, int digits, int flags = 0, int fill_exp = 0)

Formats a floating point number d in scientific / exponential notation (sign, single digit, period, decimal part, "e" decimal exponent) with given number of digits. flags can be a binary combination (|) of

 FD_SIGN always prepend sign (+10) FD_SIGN_EXP always prepend sign to exponent (1e+2) FD_CAP_E capital E for exponent (1E10) FD_ZERO keep trailing zeros (1.25000)

fill_exp is left zero-padding of exponent in exponential notation

String FormatIntBase(int i, int base, int width = 0, char lpad = ' ', int sign = 0)

 Last edit by cxl on 12/02/2017. Do you want to contribute?. T++