Add , seperatation to currency information
This commit is contained in:
@@ -11,13 +11,21 @@ import kotlin.math.absoluteValue
|
||||
import kotlin.time.Duration
|
||||
|
||||
object FirmFormatters {
|
||||
fun toString(float: Float, fractionalDigits: Int): String = toString(float.toDouble(), fractionalDigits)
|
||||
fun toString(double: Double, fractionalDigits: Int): String {
|
||||
fun formatCurrency(long: Long, segments: Int = 3): String {
|
||||
val α = long / 1000
|
||||
if (α != 0L) {
|
||||
return formatCurrency(α, segments) + "," + (long - α * 1000).toString().padStart(3, '0')
|
||||
}
|
||||
return long.toString()
|
||||
}
|
||||
|
||||
fun formatCurrency(float: Float, fractionalDigits: Int): String = formatCurrency(float.toDouble(), fractionalDigits)
|
||||
fun formatCurrency(double: Double, fractionalDigits: Int): String {
|
||||
val long = double.toLong()
|
||||
val δ = (double - long).absoluteValue
|
||||
val μ = pow(10, fractionalDigits)
|
||||
val digits = (μ * δ).toInt().toString().padStart(fractionalDigits, '0').trimEnd('0')
|
||||
return long.toString() + (if (digits.isEmpty()) "" else ".$digits")
|
||||
return formatCurrency(long) + (if (digits.isEmpty()) "" else ".$digits")
|
||||
}
|
||||
|
||||
fun formatTimespan(duration: Duration): String {
|
||||
|
||||
Reference in New Issue
Block a user