UnitFormat

class UnitFormat @JvmOverloads constructor(val name: String, val singular: Component, val plural: Component, val abbreviation: Component? = null, val defaultPrefix: MetricPrefix = MetricPrefix.NONE, val defaultStyle: Style = Style.empty(), val usePrefixes: Boolean = true)(source)

Handles formatting of a specific unit. Call format to format a value using this unit.

Parameters

name

The English name of the unit (for example 'kilograms')

singular

A component representing the long singular form of this unit (kilogram, meter, liter, etc)

plural

A component representing the long plural form of this unit (kilograms, meters, liters, etc)

abbreviation

A component representing the abbreviated form of this unit (kg, m, L, etc)

defaultPrefix

The prefix (kilo, nano, etc) used for this unit unless specified while formatting. For example, if you create a 'grams' unit and specify 'kilo' as the default prefix, calling format with 100 will return '100 kilograms'

defaultStyle

The style to apply to the unit (not the value)

usePrefixes

Whether we should automatically calculate and apply a prefix (kilo, nano, etc) to the output.

Constructors

Link copied to clipboard
constructor(name: String, singular: Component, plural: Component, abbreviation: Component? = null, defaultPrefix: MetricPrefix = MetricPrefix.NONE, defaultStyle: Style = Style.empty(), usePrefixes: Boolean = true)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
inner class Formatted : ComponentLike

Represents a value that has already been formatted.

Properties

Link copied to clipboard
val abbreviation: Component? = null
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val usePrefixes: Boolean = true

Functions