I have a code that processes coordinates as 4 separate double variables (e.g. 51, 1822, 22, 2234). However, the data is stored as 2 separate double variables (e.g. 51.1822 and 22.2234)
The Whole number is always 2. and the fractions range between 1 to 6 digits.
So, how may I separate the right and left digits of the decimal point and store each into separate double variables please-?
if you mean to store into a c-string array, then something like this could work for you:
void setup() {
Serial.begin(115200);
char c_str[16]; //ensure array is big enough to store all the characters that will form the c-string
float d1 = 51.1822;
float d2 = 22.2234;
//store d1 and d2 as c-string
//values 'written' to 4dp.
//values seperated by comma (',')
sprintf(c_str, "%s,%s", String(d1, 4).c_str(), String(d2, 4).c_str());
//replace all '.' with ','
char *fnd_chr = strchr(c_str, '.');
while (fnd_chr) {
*fnd_chr = ',';
fnd_chr = strchr(fnd_chr, '.');
}
Serial.println(c_str);
}
void loop() {
// put your main code here, to run repeatedly:
}
As I alluded to in my post, @vaxman was expecting the wrong thing as a double value has a fixed number of decimal places rather than a variable number. It is the number of significant decimal places that matters