0

I'm experimenting with writing an ethereum-usd price ticker taking data from the coinmarketcap API using Oraclize's API.

I noticed that Oraclize has a function called parseInt that can be used to remove the numbers after the decimal from a string (such as 10.99) an turn it into the uint 10.

As far as I can tell this ONLY works with strings that have a FIXED length after the decimals. As per CMCs API, the length after the decimal is variable in length. I've noticed it being values such as 1000.99 or 1000.991

I'm unable to figure out how to parse this string of a variable decimal length and turn it into a whole number.

1

From my reading of the code and testing in Remix, I think you're mistaken. parseInt("1000.99") and parseInt("1000.991") should both return 1000.

There's an optional parameter that basically says what power of 10 to multiply by. parseInt("100.99", 2) and parseInt("1000.991") should both return 100099.

  • Ah yes I was indeed mistaken. Thanks for the answer that makes things a lot more clear now. – hextet Jan 23 '18 at 9:28

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.