blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
851 B
29 lines
851 B
// Copyright SIX DAY LLC. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
struct EthereumConverter {
|
|
|
|
static func from(
|
|
value: BInt,
|
|
to: EthereumUnit,
|
|
minimumFractionDigits: Int = 3,
|
|
maximumFractionDigits: Int = 3
|
|
) -> String {
|
|
//TODO: Hack. Implement better solution
|
|
|
|
let first = Double(value.dec)!
|
|
let second = Double(to.rawValue)
|
|
let third = first / second
|
|
|
|
let number = NSNumber(value: third)
|
|
let formatter = NumberFormatter()
|
|
formatter.numberStyle = .decimal
|
|
formatter.maximumFractionDigits = max(maximumFractionDigits, minimumFractionDigits)
|
|
formatter.minimumFractionDigits = minimumFractionDigits
|
|
formatter.roundingMode = .floor
|
|
let formattedAmount = formatter.string(from: number)!
|
|
|
|
return formattedAmount
|
|
}
|
|
}
|
|
|