aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-31 23:19:30 +0200
committernea <nea@nea.moe>2023-08-31 23:19:30 +0200
commit36d5ef29e45a57e88d9d608d1becb5cb7de27cf5 (patch)
treeecf7df1eaa4feffee6786e5cc62a5305c28963e9 /src/main/kotlin/moe/nea/firmament/util
parentece429c361b0ac30490d74ec33c6ef4a74a1fc5d (diff)
downloadFirmament-36d5ef29e45a57e88d9d608d1becb5cb7de27cf5.tar.gz
Firmament-36d5ef29e45a57e88d9d608d1becb5cb7de27cf5.tar.bz2
Firmament-36d5ef29e45a57e88d9d608d1becb5cb7de27cf5.zip
Add , seperatation to currency information
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt b/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt
index b2c1f35..96a4389 100644
--- a/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt
@@ -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 {