Hello!
I am not sure how to convert a String to an int... I tried toInt() but it seems to give a value which I can't interpret. Speaking of Python, there is an int() function by which we can easily convert "1" to 1 or even "123456" to 123456. And that's exactly what I want to do using Arduino IDE...
An int is 16 bits which means it can range from -32768 to +32767. Your number is larger than that.
If you made it an unsigned int then it would be 0..65536 which is still too small.
If you made it a long, then you have 32 bits and it will work but you can no longer use .toInt() but you can use .toFloat() and, if your variable is a long, it will be converted from a floating point number into a long integer
Or, you could go 'classic' and do the conversion yourself, processing each character until you encounter something other than 0-9. Sounds like work, though...
I think it has to do with floating-point rounding error, and that pow() computes using an approximation (I'm guessing using exp() and log() internally). If you want integer math, you have to use integer math, at least in this case.
More likely, just the actual numeric accuracy of floats in this instance, not 'rounding error' per se. But I'm not interested enough to look under the covers, the OP should, if curious, do so.
When I try to add a String variable instead of a String in line 1 of the code you've mentioned, I get an error:
error: cannot convert 'String' to 'char' in initialization
char pluto[] = {test};
^
exit status 1
cannot convert 'String' to 'char' in initialization
Hope there is a way to add a String variable instead of a direct String...
Or else, for me the whole point of this conversion won't help! Sorry for not mentioning that I needed to convert a String variable. Technically, both should mean the same thing though...
String text="123456"; // the String you want to convert to a char array
char pluto[11]; // the char array you want to hold the string
// make sure that the char array is big enough
// I made it size 11 which is enough for a string of 10 characters
strcpy(pluto, text.c_str()); // this line does the conversion to char array