0

I have the following code snippet inside my contract:

plans[1100] = Plan(7, 3);
plans[1101] = Plan(7, 2.5);
plans[1102] = Plan(15, 4);
plans[1103] = Plan(30, 6);
plans[1104] = Plan(30, 5);

When I try to compile my contract, I encounter the following error:


CompileError: /home/nimashiri/react-dapp/contracts/TrustTrade.sol:172:31: TypeError: Invalid type for argument in function call. Invalid implicit conversion from rational_const 5 / 2 to uint256 requested.
plans[1101] = Plan(7, 2.5);

I was wondering if you help me with this case.

Thanks, Nima.

3
  • What is Plan? Solidity doesn't have floating point support. It does work for intermediate results when the final is an integer. For example uint256 a = 2.5 * 1000 works but it fails for uint256 a = 5 / 3 * 1000 fails.
    – Ismael
    Commented Feb 16, 2021 at 6:04
  • @Ismael Thanks. Sorry, i forgot to mention Plan. It is a struct: ` struct Plan {uint256 period; uint256 interest;}`
    – Nima shiri
    Commented Feb 16, 2021 at 16:48
  • The error is that you are trying to assign 2.5 to an uint256. Solidity is trying to be helpful and don't let you assign it.
    – Ismael
    Commented Feb 16, 2021 at 18:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.