why double is Rounding

Hi,

why ...

double p = 3.141592;

void loop()

{
  serial.prinln(p);
}

return 3.14

Thanks

ES

Serial.println() defaults to printing 2 decimal places. Add a second parameter of the number of decimal places you want to print

Serial.println(p, 4);

for instance

See Serial.print() - Arduino Reference

How much do you want -- all 6-digit precision after the decimal point?

Serial.print(arg1, arg2);

If arg1 is a floating point number, then arg2 indicates the number of digits to be printed after the decimal point. Hope, you have got the clue of seeing 3.141592 on the Serial Monitor.

thanks for your fast response.

I am a beginner, a great beginner.

And I'm surprised the answer! 2 digits for double precision

I thought I had zeros or rounding errors.

'println' converted to a character

Thanks to you two

ES

Closed

From the Arduino Serial.print reference;

"Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is."

Also note, on a lot of Arduino's a double is the same as a float and is 32-bit. And a 32-bit float has around a maximum precision of 6 digits (not decimals!). In most cases it's better (aka more precise and faster) to stick to integers. A float is NOT just simply a decimal point :wink: