@@ -24,23 +24,50 @@ import java.time.ZoneId
2424import java.time.ZonedDateTime
2525import java.time.format.DateTimeFormatter
2626import java.util.*
27+ import kotlin.math.floor
28+ import kotlin.math.pow
2729
2830object Formatting {
31+ @Deprecated(" Use asString with decimals and locale parameters instead" , ReplaceWith (" asString(decimals, locale)" ))
2932 val Vec3d .string: String
3033 get() = asString()
3134
35+ @Deprecated(" Use asString with decimals and locale parameters instead" , ReplaceWith (" asString(decimals, locale)" ))
3236 val Float .string: String
33- get() = " %.2f" .format(Locale .US , this )
37+ get() = " %, .2f" .format(Locale .US , this )
3438
39+ @Deprecated(" Use asString with decimals and locale parameters instead" , ReplaceWith (" asString(decimals, locale)" ))
3540 val Double .string: String
36- get() = " %.2f" .format(Locale .US , this )
41+ get() = " %, .2f" .format(Locale .US , this )
3742
38- fun Vec3d.asString (decimals : Int = 2): String {
39- val format = " %.${decimals} f"
40- return " (${format.format(Locale .US , x)} , ${format.format(Locale .US , y)} , ${format.format(Locale .US , z)} )"
43+ fun Double.asString (decimals : Int = 2, locale : Locale = Locale .US , numberGrouping : Boolean = true): String {
44+ val format = if (numberGrouping) " %,.${decimals} f" else " %.${decimals} f"
45+ val factor = 10.0 .pow(decimals)
46+ val floored = floor(this * factor) / factor
47+ return format.format(locale, floored)
4148 }
4249
43- fun BlockPos.asString () = " ($x , $y , $z )"
50+ fun Vec3d.asString (decimals : Int = 2, locale : Locale = Locale .US , numberGrouping : Boolean = true): String {
51+ val format = if (numberGrouping) " %,.${decimals} f" else " %.${decimals} f"
52+ val vec = floorToDecimals(this , decimals)
53+ return " (${format.format(locale, vec.x)} ${format.format(locale, vec.y)} ${format.format(locale, vec.z)} )"
54+ }
55+
56+ private fun floorToDecimals (vec : Vec3d , decimals : Int ): Vec3d {
57+ val factor = 10.0 .pow(decimals)
58+ return Vec3d (
59+ floor(vec.x * factor) / factor,
60+ floor(vec.y * factor) / factor,
61+ floor(vec.z * factor) / factor
62+ )
63+ }
64+
65+ fun BlockPos.asString (decimals : Int = 2, locale : Locale = Locale .US , numberGrouping : Boolean = true): String {
66+ val x = x.toDouble().asString(decimals, locale, numberGrouping)
67+ val y = y.toDouble().asString(decimals, locale, numberGrouping)
68+ val z = z.toDouble().asString(decimals, locale, numberGrouping)
69+ return " ($x $y $z )"
70+ }
4471
4572 fun getTime (formatter : DateTimeFormatter = DateTimeFormatter .RFC_1123_DATE_TIME ): String {
4673 val localDateTime = LocalDateTime .now()
0 commit comments