Updated on 2026-08-14
This commit is contained in:
commit
4516a76ad3
15 changed files with 322 additions and 124 deletions
|
|
@ -0,0 +1,21 @@
|
|||
package com.tangem.utils
|
||||
|
||||
import java.math.BigDecimal
|
||||
import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
import java.text.DecimalFormatSymbols
|
||||
import java.util.*
|
||||
|
||||
fun BigDecimal.toFormattedString(
|
||||
decimals: Int, roundingMode: RoundingMode = RoundingMode.DOWN, locale: Locale = Locale.US,
|
||||
): String {
|
||||
val symbols = DecimalFormatSymbols(locale)
|
||||
val df = DecimalFormat().apply {
|
||||
decimalFormatSymbols = symbols
|
||||
maximumFractionDigits = decimals
|
||||
minimumFractionDigits = 0
|
||||
isGroupingUsed = false
|
||||
this.roundingMode = roundingMode
|
||||
}
|
||||
return df.format(this)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue