PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 21, 2022

[FIXED] How to declare the "b variable" as negative?

 July 21, 2022     blockchain, integer, solidity     No comments   

Issue

I'm trying to declare the value as a negative number, but I'm not quite sure how to do this.

pragma solidity ^0.8.4;

contract Contract {
    int8 public a;
    int8 public b;
    int16 public difference = a - -b;
}

Solution

You can't give a negative number to uint, instead you should use int.

What you are looking for:

contract Contract {
    int8 public a = 3;
    int8 public b = -3;
    int16 public difference = a - -b;
    //If it did not work, change above line to this:
    //int16 public difference = a - b;
}


Answered By - Ahmad Gorji
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing