Decimal places variables

i have not been working with the arduino for long and i currently have the problem that my calculations are rounded and therefore i have an inaccurate result.

is there any change to define the number of decimal places after the comma?


Posting images of code is not very good. Posting snippets of code is not very good. Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

The quickest way to get help is to post a minimal verifiable code that exhibits the problem.

If you want to print more (or less) than 2 decimal places use (see the print reference):

Serial.print(floatNumber, decimal_places);
Serial.print(AcX1,4);  // prints 4 decimal places

Floats in Arduino are only 6 significant digits so are not as accurate as you may want.

From the reference on the float data type.

The float data type has only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float.

You can specify the number of digits printed after the decimal point (or comma):

float x=1.23456;
Serial.println(x, 4);

as shown in the screenshot (sorry for that), I would like to calculate the arc cosinus of a number. However, since the calculation before has an accuracy to two decimal places, this calculation is very inaccurate:

0.99 --> 8 degrees
0.999 --> 0.8 degrees

is there a possibility to use at least 4 - 5 digits for the arc cosinus calculation?

You misunderstand. The PRINTING controls how many decimal places you see. Internally, 6 or 7 decimal places are used, in a single precision AVR Arduino.

It is doing the best it can. You are confusing how many digits are being printed with how many are maintained in the float variable.

As @groundFungus notes, about 7 or 6 sig figures.


oh yes that's right. it's actually the reading that has the big deviation here. Thanks a lot for your help