Last active
March 8, 2017 16:07
-
-
Save sciguy16/6b742da26cf02b332e7e8d9c9b156ae3 to your computer and use it in GitHub Desktop.
Julia program for converting values between wei, shannon, szabo, finney and ether. Written for Julia 0.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multipliers = Dict("w" => 1, # wei | |
"sh" => 1000000000, # shannon | |
"z" => 1000000000000, # szabo | |
"f" => 1000000000000000, # finney | |
"t" => 1000000000000000000) # eth | |
# smallest substrings to search for that uniquely identify | |
function UnitToWei(st) | |
pos = search(st,' ') # get index of space | |
if pos == 0 # we are already in wei | |
return parse(Float64,st) | |
else | |
val = parse(Float64,st[1:pos-1]) | |
for multiplier in keys(multipliers) | |
if contains(st,multiplier) | |
return val*multipliers[multiplier] | |
end | |
end | |
end | |
end | |
print("Enter USD for 1 ETH (about 17.64 on 8/3/17): ") | |
usd = parse(Float64,readline()) | |
for line in eachline() | |
valueinwei = UnitToWei(line) | |
println() | |
println("$valueinwei wei") | |
println(valueinwei/1000000000," shannon") | |
println(valueinwei/1000000000000," szabo") | |
println(valueinwei/1000000000000000," finney") | |
println(valueinwei/1000000000000000000," ether") | |
println(usd*valueinwei/1000000000000000000," USD") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment