1

This value cannot be negative, can it? I am annoyed because I cannot cast this to an int or do not know how to.

2 Answers 2

2

msg.value can not be negative.

you can simply cast msg.value to int like this

 int castedValue = (int) (msg.value);
0

because msg.value refers to the amount of wei(eth in gas smallest unit) you're sending to the recipient.

Do you have negative amounts on your account ? not sure about that. + you can cast it to an int with traditional manual typecasting.

3
  • So it's possible to send a negative amount? Commented Feb 10, 2023 at 7:23
  • you can cast the original value to an int, but the type of msg.value is unsigned int. So no you can't
    – Raphael
    Commented Feb 10, 2023 at 18:29
  • 1
    an unsigned int is 256 bit, from 0 to (2 power of 256 )-1
    – Raphael
    Commented Feb 10, 2023 at 18:31

Your Answer

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

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