"cout" a double with no decimals

Hi all!

I have a problem writing a double with no decimals. I know how to decrease decimals with setprecision and fixed.

for example

double one = 3.414, two = 3.514;

cout << one <" " <<two;

How to make the outcome 3 4?

thanks for any help at all!
cout << std::setprecision(0) << one << " " <<two;
thx! :)

it doesn´t seem to work tho..?
works for me:
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <iomanip>

int main()
{
	double x = 2.44, y = 3.1123;
	std::cout << std::setprecision(0) << x << " " << y << std::endl;
	return 0;
}
closed account (3TXyhbRD)
1
2
3
4
5
6
7
8
#include <iostream>
#include <iomanip>

int main()
{
    double one = 3.414, two = 3.514;
    std::cout << std::setprecision(1) << one << ' ' << two << std::endl;
}
closed account (3qX21hU5)
What doesn't work? Could you post the code you have so we can see whats wrong? Because it should work.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <cmath>

int main ()
{
    double a = 3.414, b = 3.514 ;

    // std::llround(): round away from zero, to long long
    std::cout << std::llround(a) << " " << std::llround(b) << '\n' // 3 4
              << std::llround( -a ) << " " << std::llround( -b ) << '\n' ; // -3 -4
}
Topic archived. No new replies allowed.