I'm using an oraclize contract and would like to convert the string result to an integer, but somehow keep track of the decimal places (like show multiplied by 1000).
Say for instance the result is "290.025", I would like to get 290025 as the int.
Here is the oraclize call back code that doesn't work:
function __callback(bytes32 _oraclizeID, string _result) {
require(msg.sender == oraclize_cbAddress());
Value = mul(parseInt(_result),1000);
}
The problem here is that parseInt (an oraclize function) drops the decimal places. So how do I convert string to int and keep the decimal places for multiplication?
Best Answer
Thomas from Oraclize here.
parseInt
takes an optional second argument to do exactly that!To be more specific,
parseInt("290.025", 3)
will return 290025.I hope this helps!