This question has already been answered:

When I find the root in c ++, it is automatically rounded when in java to the last digit, as it can be removed and then rounded to 6 characters. Sorry for the stupid question I rummage in java more. I use with ++ 11

double dist(point x, point y) { return sqrt((xx-yx) * (xx-yx) + (xy-yy) * (xy-yy));} 

This method returns a number with 5 digits after the decimal point, although there are more, how do I get the full number to be returned?

Reported as a duplicate by the participants αλεχολυτ , user194374, Harry c ++ Feb 7 '17 at 11:58 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • isn't it? - Mike V.
  • @MikeV. I meant how to increase double - Dmitry Belousov
  • write more precisely in the question: what is and what is needed - Mike V.
  • @MikeV. changed everything - Dmitry Belousov
  • one
    This method does NOT "return a number with 5 digits after the decimal point." Double type has no fixed number of digits at all. Obviously, it’s you yourself then print your number with “with 5 digits after comma”, but this has no relation to “this method”. - AnT

1 answer 1

How do you display the value?
How to cout << x ?
But the default is 6 characters. Your problem is not that double inaccurate, but that you inaccurately output it.

Try, for example, like this:

 cout << setprecision(12) << x; 
  • and how can printf be used to output - Dmitry Belousov
  • and to be rounded down to a lesser degree - Dmitry Belousov
  • 2
    For example, as printf("%.10lf\n",x); . See here - ru.cppreference.com/w/cpp/io/c/fprintf - Harry