I am trying to convert a string to a float or double, however none of the standard C/C++ methods seem to work. I have tried:
atof
strtof
strtod
sscanf
In each case, I get an error message when trying to do cleos set contract...
along the lines of:
Error 3070000: WASM Exception
Error Details:
env.strtod unresolveable
pending console output:
Is there a way to convert a string to a float or double that I can use?
eosio::string_to_name()
to convert a string touin64_t
and then convert that to float either using(float)
cast orstatic_cast<float>
. Note that if yourstring
isstd::string
you'd need to passeosio::string_to_name(your_string.c_str())
eosio::string_to_name()
convertschar
s to their binary representation and then sticks that into the uint64_t. So although it does give a number, the number would just be the combination of the ASCII codes from the string. Additionally it wouldn't be able to deal with decimal points, or negative numbers that start with the minus symbol.