# Output correct in console but wrong in cvui::printf

**URL:** <https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724>\
**Category:** C++\
**Tags:** cvui\
**Created:** [August 11, 2021, 5:30pm UTC](https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724 "2021-08-11T17:30:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rg0001](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@rg0001](https://forum.opencv.org/u/rg0001)\
**Post date:** [August 11, 2021, 5:30pm UTC](https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724/1 "2021-08-11T17:30:07Z")

</div>

Values 9, 5 , 10 fine to console. printf vals of the same are all zeros.:

```auto
main{
...
            double detObj = 9;
			double other_x = 5, other_y = 10;
			std::cout << "Object nums:" << detObj << std::endl;
            std::cout << "Other nums:" << other_x << other_y << std::endl;
			cvui::printf(frame, 360, 460, "detObj : %d", objsDetected, .5);
            cvui::printf(frame, 360, 500, "other output : %d and %d", other_x, other_y, .5);

}

```

When I execute the program the console shows 9, 5, 10 as expected. But if I printf the same values, they all turn up 0. I’m sure this is something simple, nonetheless -

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 11, 2021, 7:30pm UTC](https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724/2 "2021-08-11T19:30:01Z")

</div>

1. don’t expect support for `cvui` here. it’s a third party library.
2. you aren’t showing what data type `objsDetected` is
3. the format strings don’t match the data types

---

<div class="post-metadata">

**Author:** ![rg0001](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@rg0001](https://forum.opencv.org/u/rg0001)\
**Post date:** [August 11, 2021, 8:46pm UTC](https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724/3 "2021-08-11T20:46:26Z")

</div>

> [@rg0001](#):
>
> `cvui::printf(frame, 360, 460, "detObj : %d", objsDetected, .5);`

Sorry, no problem, thanks for your time anyway. I will try to avoid that in the future, for sure.

I changed the data type-\> objsDetected to detObj (above)and still the same output, corrected.

> 1. the format strings don’t match the data types

Please tell me what do you mean here exactly? Am I making an error in prinft with %d as double?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 11, 2021, 9:48pm UTC](https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724/4 "2021-08-11T21:48:12Z")

</div>

> [@rg0001](#):
>
> Please tell me what do you mean here exactly? Am I making an error in prinft with %d as double?

yes. %d isn’t “double”, it’s practically integer (“decimal”). if you want floats/doubles, you need a different format code. I won’t tell you because you should have looked up `printf` to learn about printf-style format strings

---

<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:** [August 11, 2021, 10:34pm UTC](https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724/5 "2021-08-11T22:34:35Z")

</div>

[https://en.cppreference.com/w/c/io/fprintf](https://en.cppreference.com/w/c/io/fprintf)

(`%d` is for integer, for double you want `%f`)

---

<div class="post-metadata">

**Author:** ![rg0001](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@rg0001](https://forum.opencv.org/u/rg0001)\
**Post date:** [August 12, 2021, 2:24pm UTC](https://forum.opencv.org/t/output-correct-in-console-but-wrong-in-cvui-printf/4724/6 "2021-08-12T14:24:53Z")

</div>

Worked great, thank you.
