Converting from Float to Int yielding weird results. What am I doing wrong? So I am trying to take GPS data with a Neo 6M gpsmodule (that is what is covered up by the square for privacy sake) and process it by adding/multiplying to get large integers representing the GPS data. This is using Arduino nano. When I try and convert the float numbers to integers, it gives me totally different numbers. 1242895 turns into -2289, and 611194 turns into 21370. I have tried so many things, but am stumped as to what is going on. Is it related to pointing? It's been awhile since I learned about pointers in my C++ class. X and Y are initialized as int global variables.
On an Arduino board with the 328 processor, an INT is stored as a 2 byte value, so the max number is 32,767.
You want to use a LONG which is a 4 byte number which has a max of 2,147,483,647.
When the variable you are using is not big enough, the number rolls over, which is why you end up getting a negative number.