0

serialize support for float types is not added in flutter and thats why i have to come to this way,so if anyone have any working example for this,ill be really thankful for that.

I have tried this way but error is coming

void mainloan::adduwr(name acc_name, string interestString, uint64_t loan_amount )
{
  print("Adding underwriter", acc_name);

 eosio::print("Interest String",interestString);
 double interestFloat=atof(interestString);
 eosio::print("Interest Double",interestFloat);

  uwr_table.emplace(get_self(), [&](auto &u) {
    u.acc_name = acc_name;
    u.interest_rate =interestFloat;
    // u.loan_amount=loan_amount;
    u.giving_loan_amunt = loan_amount;
  });
}

Table

 struct [[eosio::table]] underwriter_info
  {
    name acc_name;
      double interest_rate;
      uint64_t giving_loan_amunt;
    auto primary_key() const
    {
      return acc_name.value;
    }
  };

ERROR

 error: no viable conversion from 'std::__1::string' (aka 'basic_string<char,
      char_traits<char>, allocator<char> >') to 'const char *'
 double interestFloat=std::atof(interestString);
0

1 Answer 1

1

If your string is always a double number

// Convert to double mannualy because stod throws "out of memory bound" error in EOS 
string in = "5.2";
std::size_t input_dot_index = in.find(".");

int64_t input_digits = in.length() - input_dot_index - 1;

in.erase(input_dot_index, 1);
double converted = atoi(in.c_str()) / pow(10, input_digits);

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