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.

float to int issue

  • 2
    Please copy and paste your code here instead of posting a screenshot. A picture of some text is about the most useless thing on the internet. It can't be copied and edited. It's hard to read. Screen readers can't touch it. Please in the future just copy and paste the text itself.
    – Delta_G
    Commented Sep 18, 2020 at 2:03
  • Covered up for privacy sake? You are sharing the same data below, with only a trivial transformation. Commented Sep 18, 2020 at 7:48

1 Answer 1


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.

  • 1
    I've fixed up the capitalization in your post, but in future please try to make English sentences. They start with a capital letter. This isn't a game chat where you just type in all lower-case.
    – Nick Gammon
    Commented Sep 19, 2020 at 7:49
  • 1
    @NickGammon Wow. Thank you so much.
    – Chad G
    Commented Sep 21, 2020 at 23:37

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.