-1

This question already has an answer here:

contrast take{ if ((address(this).balance)/100>=1/100){ } }

The code above throws type error: incompatible type between uint256 and rational_const 1/100.does anyone know how to solve that?

marked as duplicate by Ismael, Crissi Mariam Robert, shane, kherwa, Achala Dissanayake Jul 10 at 17:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You should actually consider yourself lucky that it throws this error, because this code is really bad regardless of that. The expression 1/100 would be compiled to 0 in Solidity, since there are no floating-point types (in fact, even in languages which do support floating-point types, this expression as stated would yield zero, since it uses only integers). – goodvibration Jul 7 at 11:19
  • In any case, here is an idea for you - it seems that you can simply remove the /100 on both sides of the expression. – goodvibration Jul 7 at 11:21
  • And by the way, what does contrast take followed by an if statement inside curly braces even mean??? Your question is very poorly-phrased! – goodvibration Jul 7 at 11:22
  • @goodvibration I think it would be nice to be polite especially to new contributors. – Lauri Peltonen Jul 7 at 11:25
  • 1
    @LauriPeltonen: I agree, so I apologize. And I also think that it would be useful not to encourage such low effort in writing a question (encourage by answering such questions) . There are more syntax errors in this question than there are characters, the code is not compilable for several different reasons, and the question in whole doesn't seem to be very contributive (dividing by 100 on both sides???). – goodvibration Jul 7 at 11:29
1

Solidity doesn't understand fractional numbers and it doesn't support them. In order for it to make the comparison you are doing it would need to store a fractional number at the right hand side and that's not possible.

The obvious solution is to just multiple both side by 100 and therefore it becomes if (address(this).balance >= 1).

Furthermore, as you are comparing Ether balances, keep in mind that 1 as a balance means 1 wei. To be clear you should always write that explicitly so it becomes if (address(this).balance >= 1 wei) Also you have a typo in your code, you should use the keyword contract instead of contrast

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