Concept of infinity, for Decimals
This commit is contained in:
parent
6784271ac7
commit
f13c725298
File diff suppressed because it is too large
Load Diff
@ -167,6 +167,8 @@ fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsR
|
|||||||
|
|
||||||
fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component {
|
fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component {
|
||||||
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
|
||||||
|
if (this == Decimal.POSITIVE_INFINITY) return concat("∞", suffix)
|
||||||
|
if (this == Decimal.NEGATIVE_INFINITY) return concat("-∞", suffix)
|
||||||
if (formatAsReadable.asBoolean && this.absoluteValue >= Decimal.ONE) return concat(reformat(toString(decimalPlaces)), suffix)
|
if (formatAsReadable.asBoolean && this.absoluteValue >= Decimal.ONE) return concat(reformat(toString(decimalPlaces)), suffix)
|
||||||
val prefix = SiPrefix.determine(this)
|
val prefix = SiPrefix.determine(this)
|
||||||
return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, (this / prefix.decimal).toString(decimalPlaces), suffix)
|
return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, (this / prefix.decimal).toString(decimalPlaces), suffix)
|
||||||
|
@ -121,7 +121,7 @@ enum class SiPrefix(val power: Int, val symbol: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun determine(value: Decimal, bias: Int = 0): SiPrefix {
|
fun determine(value: Decimal, bias: Int = 0): SiPrefix {
|
||||||
if (value.isZero) {
|
if (value.isZero || value.isInfinite) {
|
||||||
return NONE
|
return NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user