double n=12345678;
n=n*0.000001;
Serial.print(n,12); //12 is to view the fractional nos

Here the answer is not 12.345678000000, but have some more decimal digits like 12.345678154896.
How to solve this? I want the exact value as mentioned (12.345678).

devanpvasudevan:
double n=12345678;
n=n*0.000001;
Serial.print(n,12); //12 is to view the fractional nos

Here the answer is not 12.345678000000, but have some more decimal digits like 12.345678154896.
How to solve this? I want the exact value as mentioned (12.345678).

If you only need 8 digits you can use unsigned long integers and do the math fixed point style.

Here's an example. I want to divide 696 by 12.345678.

12.345678 is 12,345,678 / 1,000,000.

long x = 696;
long result = x * 1000000L / 12345678L; // must do the multiplication first!

Note, however, that the result is an integer, 56. Not 56.376004622832379072255083924917... Fixed point math is a lot more hands-on than with floating point and each calculation has to be tailored for the task at hand. But in many cases, it's a much better choice because it's faster and leaner.

In this example, the limiting factor was the 31 bit maximum size of a long, and the fact that the product of two numbers uses about double the number of bits. The divisor wouldn't fit in 15 bits. But I could do:

long x = 696;
long result = x * 1000000L / 12345L; // must do the multiplication first!

and the integer result is 56379. The assumed decimal place is three digits to the left, so 56.379 is the actual result.

It is a double not a float.
I'm working with a GPS module and want to process Latitude and Longitude data which have 6 decimal digits.

I wish to process them in their own structure (6 decimal points and total 8 digits) or else I can use them as simply 8 digit integer. So what should I do?

devanpvasudevan:
It is a double not a float.
I'm working with a GPS module and want to process Latitude and Longitude data which have 6 decimal digits.

I want to process them in their own structure (6 decimal points and total 8 digits) or else I can use them as simply 8 digit integer. So what should I do?

I would keep it in 8 digit integers. More precision with unsigned long than float.