or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

file-size.mdindex.mdnumber-formatting.mdpluralization-lists.mdstring-operations.mdutility-functions.md
tile.json

number-formatting.mddocs/

Number Formatting

Functions for formatting numbers with thousand separators, compact notation, ordinals, and bounded values.

Capabilities

Integer with Commas

Converts an integer to a string containing commas every three digits.

/**
 * Converts an integer to a string containing commas every three digits
 * @param number - Number to format
 * @param decimals - Number of decimal places (default: 0)
 * @returns Formatted number string with commas
 */
function intComma(number: number, decimals?: number): string;

Usage Examples:

const Humanize = require('humanize-plus');

console.log(Humanize.intComma(1234567)); // "1,234,567"
console.log(Humanize.intComma(1234567.89, 2)); // "1,234,567.89"
console.log(Humanize.intComma(1000)); // "1,000"

Compact Integer

Converts an integer into its most compact representation using k, M, B, T suffixes.

/**
 * Converts an integer into its most compact representation
 * @param input - Integer to convert
 * @param decimals - Number of decimal places (default: 0)
 * @returns Compact string representation
 */
function compactInteger(input: number, decimals?: number): string;

Usage Examples:

const Humanize = require('humanize-plus');

console.log(Humanize.compactInteger(1000)); // "1k"
console.log(Humanize.compactInteger(1234567, 1)); // "1.2M"
console.log(Humanize.compactInteger(1000000000, 2)); // "1.00B"
console.log(Humanize.compactInteger(999)); // "999"

// Very large numbers use scientific notation
console.log(Humanize.compactInteger(7832186132456328967, 2)); // "7.83x10^18"

Custom Number Formatting

Formats a number with customizable thousand and decimal separators.

/**
 * Formats a number to a human-readable string with custom separators
 * @param number - Number to format
 * @param precision - Number of decimal places (default: 0)
 * @param thousand - Thousands separator (default: ',')
 * @param decimal - Decimal separator (default: '.')
 * @returns Formatted number string
 */
function formatNumber(
  number: number, 
  precision?: number, 
  thousand?: string, 
  decimal?: string
): string;

Usage Examples:

const Humanize = require('humanize-plus');

console.log(Humanize.formatNumber(1234567.89, 2)); // "1,234,567.89"
console.log(Humanize.formatNumber(1234567.89, 2, ' ', ',')); // "1 234 567,89"
console.log(Humanize.formatNumber(1234567, 0, '.')); // "1.234.567"

Ordinal Numbers

Converts an integer to its ordinal representation as a string.

/**
 * Converts an integer to its ordinal as a string (1st, 2nd, 3rd, etc.)
 * @param value - Integer to convert
 * @returns Ordinal string representation
 */
function ordinal(value: number): string;

Usage Examples:

const Humanize = require('humanize-plus');

console.log(Humanize.ordinal(1)); // "1st"
console.log(Humanize.ordinal(2)); // "2nd"
console.log(Humanize.ordinal(3)); // "3rd"
console.log(Humanize.ordinal(4)); // "4th"
console.log(Humanize.ordinal(21)); // "21st"
console.log(Humanize.ordinal(22)); // "22nd"
console.log(Humanize.ordinal(11)); // "11th" (special case)
console.log(Humanize.ordinal(12)); // "12th" (special case)
console.log(Humanize.ordinal(13)); // "13th" (special case)

Bounded Numbers

Truncates a number to an upper bound with a customizable suffix.

/**
 * Bounds a value from above with customizable ending string
 * @param num - Number to bound
 * @param bound - Upper limit (default: 100)
 * @param ending - Suffix for bounded values (default: '+')
 * @returns String representation, bounded if necessary
 */
function boundedNumber(num: number, bound?: number, ending?: string): string;

Usage Examples:

const Humanize = require('humanize-plus');

console.log(Humanize.boundedNumber(150, 100)); // "100+"
console.log(Humanize.boundedNumber(50, 100)); // "50"
console.log(Humanize.boundedNumber(1000, 500, ' max')); // "500 max"

Deprecated Functions

intword (DEPRECATED)

/**
 * @deprecated Use compactInteger instead. Will be removed in next major version.
 */
function intword(number: number, charWidth: any, decimals?: number): string;

intcomma (DEPRECATED)

/**
 * @deprecated Use intComma instead. Will be removed in next major version.
 */
function intcomma(...args: any[]): string;

truncatenumber (DEPRECATED)

/**
 * @deprecated Use boundedNumber instead. Will be removed in next major version.
 */
function truncatenumber(...args: any[]): string;