# Mat ptr\<double\> avoid truncation

**URL:** <https://forum.opencv.org/t/mat-ptr-double-avoid-truncation/6581>\
**Category:** C++\
**Tags:** core\
**Created:** [December 6, 2021, 5:46am UTC](https://forum.opencv.org/t/mat-ptr-double-avoid-truncation/6581 "2021-12-06T05:46:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee\_0111](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lee_0111/32/3947_2.png) [@lee\_0111](https://forum.opencv.org/u/lee_0111)\
**Post date:** [December 6, 2021, 5:46am UTC](https://forum.opencv.org/t/mat-ptr-double-avoid-truncation/6581/1 "2021-12-06T05:46:52Z")

</div>

When I take values of a Mat use ptr(r)[c]，decimals are reserved for two significant digits.How to avoid truncation of numbers?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 6, 2021, 7:38am UTC](https://forum.opencv.org/t/mat-ptr-double-avoid-truncation/6581/2 "2021-12-06T07:38:34Z")

</div>

can you show example code to reproduce it, please ?

---

<div class="post-metadata">

**Author:** ![lee\_0111](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lee_0111/32/3947_2.png) [@lee\_0111](https://forum.opencv.org/u/lee_0111)\
**Post date:** [December 6, 2021, 8:52am UTC](https://forum.opencv.org/t/mat-ptr-double-avoid-truncation/6581/3 "2021-12-06T08:52:35Z")

</div>

Mat cameraMatrix;  
FileStorage fs("./calibrate.xml",FileStorage::READ);  
fs[“distCoeffs”]\>\>distCoeffs;  
fs[“cameraMatrix”]\>\>cameraMatrix;  
fs.release();  
cout\<\<cameraMatrix\<\<endl;  
// [1469.755863637623, 0, 800.3226944488998;

```
0, 1463.060248847902, 604.1622846498016;

0, 0, 1]

```

cout\<\<cameraMatrix.ptr(0)[0]\<\<endl;  
// I got 1469.76 ,but not 1469.755863637623. How to get 1469.755863637623?  
Thanks!

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 6, 2021, 9:04am UTC](https://forum.opencv.org/t/mat-ptr-double-avoid-truncation/6581/4 "2021-12-06T09:04:10Z")

</div>

the `<<` operator for cv::Mat is [changing the precision](https://en.cppreference.com/w/cpp/io/manip/setprecision) (for printing) internally.  
you can do the same:

```auto
double d = 12.3456789;
cout << d << endl; // default is 6 digits
cout << std::setprecision(10) << d << endl;

12.3457
12.3456789

```

---

<div class="post-metadata">

**Author:** ![lee\_0111](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lee_0111/32/3947_2.png) [@lee\_0111](https://forum.opencv.org/u/lee_0111)\
**Post date:** [December 6, 2021, 9:15am UTC](https://forum.opencv.org/t/mat-ptr-double-avoid-truncation/6581/5 "2021-12-06T09:15:35Z")

</div>

Thank you for your very clear and timely answer to this question~
