2023-12-11 01:20:32 -08:00
|
|
|
@file:Suppress("ktlint:standard:filename")
|
2023-10-04 05:04:08 -07:00
|
|
|
|
|
|
|
package cash.z.ecc.sdk.extension
|
|
|
|
|
|
|
|
import cash.z.ecc.android.sdk.model.MonetarySeparators
|
|
|
|
import cash.z.ecc.android.sdk.model.PercentDecimal
|
|
|
|
import java.math.RoundingMode
|
|
|
|
import java.text.DecimalFormat
|
|
|
|
|
|
|
|
@Suppress("MagicNumber")
|
|
|
|
fun PercentDecimal.toPercentageWithDecimal(decimalFormat: DecimalFormat = preparePercentDecimalFormat()): String {
|
|
|
|
return decimalFormat.format(decimal * 100)
|
|
|
|
}
|
|
|
|
|
2023-12-11 01:20:32 -08:00
|
|
|
private fun preparePercentDecimalFormat(): DecimalFormat =
|
|
|
|
DecimalFormat().apply {
|
|
|
|
val monetarySeparators = MonetarySeparators.current()
|
|
|
|
val localizedPattern = "##0${monetarySeparators.decimal}00"
|
|
|
|
applyLocalizedPattern(localizedPattern)
|
|
|
|
roundingMode = RoundingMode.HALF_UP
|
|
|
|
}
|