0

Hey Im trying to use an exchange rate gathered from json as a string to create a uint variable similar to the rate, but I need a way to capture the information after the decimal. For instance I want "1.45" to end up as "145" or something similar. Is this possible?

1

Decide how many decimal places you want and multiply by that number. That way your contract can work in uints internally. At Reality Keys we publish data like this:

https://www.realitykeys.com/exchange/11353 (Look under "See how we will sign".)

Alternatively the Solidity docs mention a real type.

  • This isn't useful without some way to import the number from the string to an uint. Like how do I multiple "1.45" as a string by 100 for instance then save it as a uint. I need some way to parse the string will retaining the .45. – Paul Harstad Nov 24 '16 at 5:11
  • Where is this string coming from in the first place? Why are you passing a string into your contract when you want it to have a number? – Edmund Edgar Nov 24 '16 at 7:20
  • If you're getting the data from Oraclize then they have a function that looks like it multiplies it out. github.com/oraclize/ethereum-api/blob/master/… It would make more sense to do it before you send it to the contract though, not sure if that's something they can do for you. – Edmund Edgar Nov 24 '16 at 7:58
  • Thanks, I was using Oraclize. They do indeed have one, which I just recently discovered. Do you know another simple way to get external data into contracts beside Oraclize? – Paul Harstad Nov 24 '16 at 20:06
  • There are a few options for exchange rates right now depending what you need: 1) There are people pushing data to contracts which you can read directly. 2) Pulling from some URL with Oraclize. 3) Get signed data from Reality Keys, send it to the contract in your DApp. – Edmund Edgar Nov 24 '16 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.