Answer the question
In order to leave comments, you need to log in
Why can't arduino multiply beyond 5 digits?
Faced with the fact that when the result of calculating a numeric variable from more than a five-digit number, arduino starts to give the wrong result.
It has 1000*10=10000 (seems to be correct)
And already 1000*100= -31072
Here is the code I used to multiply:
int _ABVAR_1_varname;
void setup()
{
_ABVAR_1_varname = 0;
Serial.begin(9600);
}
void loop()
{
_ABVAR_1_varname = ( 1000 * 100 ) ;
Serial.print( _ABVAR_1_varname );
Serial.println("");
}
Answer the question
In order to leave comments, you need to log in
Because int on it is 16-bit, and can only take values from -32768 to 32767. Replace int with long, and 1000 * 100 with 1000l * 100l and you will be (temporarily) happy.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question