|
|
|
@ -7,16 +7,17 @@ import java.text.DecimalFormat |
|
|
|
import java.text.NumberFormat |
|
|
|
import java.text.NumberFormat |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
val Number.kmbFormatted: String |
|
|
|
fun Number.kmbFormatted(threshold: Double = 10000.0): String { |
|
|
|
get() { |
|
|
|
|
|
|
|
var thousandsExponent = 0 |
|
|
|
var thousandsExponent = 0 |
|
|
|
var v = this.toDouble() |
|
|
|
var v = this.toDouble() |
|
|
|
while (abs(v) >= 10000 && thousandsExponent < 3) { |
|
|
|
if (abs(v) >= threshold) { |
|
|
|
|
|
|
|
while (abs(v) >= 1000 && thousandsExponent < 3) { |
|
|
|
v /= 1000 |
|
|
|
v /= 1000 |
|
|
|
thousandsExponent++ |
|
|
|
thousandsExponent++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val unit = when(thousandsExponent) { |
|
|
|
val unit = when (thousandsExponent) { |
|
|
|
0 -> "" |
|
|
|
0 -> "" |
|
|
|
1 -> "K" |
|
|
|
1 -> "K" |
|
|
|
2 -> "M" |
|
|
|
2 -> "M" |
|
|
|
@ -26,7 +27,7 @@ val Number.kmbFormatted: String |
|
|
|
|
|
|
|
|
|
|
|
val formatter = NumberFormat.getInstance() |
|
|
|
val formatter = NumberFormat.getInstance() |
|
|
|
return formatter.format(v) + unit |
|
|
|
return formatter.format(v) + unit |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Double |
|
|
|
// Double |
|
|
|
|
|
|
|
|
|
|
|
@ -62,12 +63,12 @@ fun Double.toRate(): String { |
|
|
|
return currencyFormatter.format(this) |
|
|
|
return currencyFormatter.format(this) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun Double.formattedHourlyDuration() : String { |
|
|
|
fun Double.formattedHourlyDuration(): String { |
|
|
|
return (this * 1000 * 3600).toLong().toMinutes() |
|
|
|
return (this * 1000 * 3600).toLong().toMinutes() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Return the time from minutes to hours:minutes |
|
|
|
// Return the time from minutes to hours:minutes |
|
|
|
fun Int.toMinutes(context: Context) : String { |
|
|
|
fun Int.toMinutes(context: Context): String { |
|
|
|
val hours = this / 60 |
|
|
|
val hours = this / 60 |
|
|
|
val minutesLeft = this % 60 |
|
|
|
val minutesLeft = this % 60 |
|
|
|
var duration = "" |
|
|
|
var duration = "" |
|
|
|
@ -84,7 +85,7 @@ fun Int.toMinutes(context: Context) : String { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Return the time from milliseconds to hours:minutes |
|
|
|
// Return the time from milliseconds to hours:minutes |
|
|
|
fun Long.toMinutes() : String { |
|
|
|
fun Long.toMinutes(): String { |
|
|
|
val totalMinutes = this / (1000 * 60) |
|
|
|
val totalMinutes = this / (1000 * 60) |
|
|
|
val hours = totalMinutes / 60 |
|
|
|
val hours = totalMinutes / 60 |
|
|
|
val minutesLeft = totalMinutes % 60 |
|
|
|
val minutesLeft = totalMinutes % 60 |
|
|
|
|