diff --git a/explorer/src/main/kotlin/com/r3corda/explorer/formatters/CurrencyFormatter.kt b/explorer/src/main/kotlin/com/r3corda/explorer/formatters/CurrencyFormatter.kt deleted file mode 100644 index a16aaab8f0..0000000000 --- a/explorer/src/main/kotlin/com/r3corda/explorer/formatters/CurrencyFormatter.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.r3corda.explorer.formatters - -import com.r3corda.core.contracts.Amount -import java.text.DecimalFormat -import java.util.* - -class CurrencyFormatter { - - companion object { - private val commaFormatter = DecimalFormat("#,###.00") - - fun currency(formatter: Formatter>) = object : Formatter> { - override fun format(value: Amount) = - "${value.token.currencyCode} ${formatter.format(value)}" - } - - val comma = object : Formatter> { - override fun format(value: Amount) = - commaFormatter.format(value.quantity / 100.0) - } - - data class KmbRange(val fromLog: Double, val toLog: Double, val letter: String, val divider: (Double) -> Double) - val kmbRanges = listOf( - KmbRange(Double.NEGATIVE_INFINITY, Math.log(1000.0), "", { value -> value }), - KmbRange(Math.log(1000.0), Math.log(1000000.0), "k", { value -> value / 1000.0 }), - KmbRange(Math.log(1000000.0), Math.log(1000000000.0), "m", { value -> value / 1000000.0 }), - KmbRange(Math.log(1000000000.0), Double.POSITIVE_INFINITY, "b", { value -> value / 1000000000.0 }) - ) - - val kmbComma = object : Formatter> { - override fun format(value: Amount): String { - val displayAmount = value.quantity / 100.0 - val logarithm = Math.log(displayAmount) - val rangeIndex = kmbRanges.binarySearch( - comparison = { range -> - if (logarithm < range.fromLog) { - 1 - } else if (logarithm < range.toLog) { - 0 - } else { - -1 - } - } - ) - val kmbRange = kmbRanges[rangeIndex] - return "${commaFormatter.format(kmbRange.divider(displayAmount))}${kmbRange.letter}" - } - } - } -}