Parsing through the individual digits of a double

Hi,

I've been working on a project to display my GPS location and I'm having some trouble trying to get the data in the right format.

The data is retrived via int latitude = GPS.latitude; in the format: 4042.6142

I am wanting to divide it so that it prints to the LCD in this format: +40° 42.6142'

I have tried:

 String lat =GPS.latitude; //// = 4042.6142
  
    Serial.print("+"); Serial.print(lat[0]); Serial.print(lat[1]);Serial.print("\"");
    for(int i = 0; i< 7; i++){
      Serial.print(lat[i+2]);
    }
    Serial.print("'");

but I get error: conversion from 'double' to non-scalar type 'String' requested

Which GPS library are you using?
You state "The data is retrived via int latitude = GPS.latitude; in the format: 4042.6142"
The type int cannot store a number with decimal places (i.e. the "4042.6142") without truncating it. You would need to use double however I would try to use a character array instead and look to use the strtok function to parse the string.
Try to stay away from the string class as past posts have shown problems with memory usage and bugs. If we can look up ythe output type(s) of the GPS library that you are using it will be easier to help.

Whoops my bad yes that should be a double.

I am using the Adafruit GPS Library GitHub - adafruit/Adafruit_GPS: An interrupt-based GPS Arduino library for no-parsing-required use

"Parsing" implies that you have a string. A float (not a double; the value is defined as a float) is not a string.

You can truncate the float as an int to get the whole part (4042). You can use division by, and modulo, 100 to get the degrees and minutes (40 and 42). Subtract the whole part from the float to get the fractional part (0.6142). Adding the minutes and fractional part will give you the parts that you want.

that should be a double.

AVR based Arduinos don't have "double." Which has given people who are doing stuff with gps no end of trouble, since apparently many of the calculations used really NEED the extra precision of "double." (which is "interesting"...)

Which has given people who are doing stuff with gps no end of trouble, since apparently many of the calculations used really NEED the extra precision of "double."

I have just received one of these: Micromega: uM-FPU64 (which I haven't connected up yet).
It does the NMEA parsing and geodetic (Haversine and crosstrack error) calculations to 64 bit precision, offloading the heavy lifting from the arduino.

"4042.6142" isn't really a valid number anyway, you are better off getting the appropriate text components and then converting to a number anyway.

note that a arduino float cannot hold 4042.6142 exactly as it has only 6~7 digits in the mantisse

in short you may enocunter rounding errors.