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

30 lines
851 B

// Copyright SIX DAY LLC. All rights reserved.
7 years ago
import Foundation
struct EthereumConverter {
7 years ago
static func from(
value: BInt,
to: EthereumUnit,
minimumFractionDigits: Int = 3,
maximumFractionDigits: Int = 3
) -> String {
//TODO: Hack. Implement better solution
7 years ago
let first = Double(value.dec)!
let second = Double(to.rawValue)
let third = first / second
7 years ago
let number = NSNumber(value: third)
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = max(maximumFractionDigits, minimumFractionDigits)
7 years ago
formatter.minimumFractionDigits = minimumFractionDigits
formatter.roundingMode = .floor
let formattedAmount = formatter.string(from: number)!
7 years ago
return formattedAmount
}
}