FIX: Use numberformatter for properly displaying the wallet balance on widget

This commit is contained in:
marcosrdz 2020-11-14 01:24:43 -05:00
parent d430f53f5d
commit d603bc222a

View file

@ -35,8 +35,16 @@ struct WalletData {
var balance: Double
var latestTransactionTime: Int = 0
var formattedBalanceBTC: String {
let formatter = NumberFormatter()
formatter.numberStyle = .none
formatter.usesSignificantDigits = true
formatter.maximumSignificantDigits = 9
let value = NSNumber(value: balance / 100000000);
return "\(value.decimalValue) BTC"
if let valueString = formatter.string(from: value) {
return "\(String(describing: valueString)) BTC"
} else {
return "0 BTC"
}
}
}