An advanced Ethereum/EVM mobile wallet
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.
 
 
 
alpha-wallet-ios/Trust/Models/EthereumConverter.swift

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
}
}