-3

I need to print rounded off integers without using exponential denotations/parts. I'm currently using this to print rounded decimal.

std::cout << std::llround(n) << n;

However, it still prints like this for big numbers

1264744611.26474e+08

Suggestions, please? And my question is different from this question as it does not take care of rounding off. On trying fixed with llround, I get numbers trailing with .000000

Community
  • 1
  • 1
TJain
  • 466
  • 1
  • 4
  • 18
  • 2
    Possible duplicate of [Making C++ cout not use scientific notation](http://stackoverflow.com/questions/5212018/making-c-cout-not-use-scientific-notation) – abhishek_naik May 23 '16 at 10:33
  • No, as it does not take care of rounding off. I just tried llround & fixed together. But got numbers trailing with .000000 – TJain May 23 '16 at 10:38
  • What exactly is the value of `n`, how do you want to print it and how does the current output differ? – eerorika May 23 '16 at 10:47
  • 2
    `std::llround` returns `long long`. It should not get formatted as floating point. Post the smallest program you can write that compiles, links, and shows the problem. – Pete Becker May 23 '16 at 11:31

1 Answers1

3

Look at what you're sending to std::cout...

std::cout << std::llround(n) << n;

...two values without any intervening punctuation or whitespace. Put a newline or something between them and I think you'll find the code is doing precisely what it should. e.g.

std::cout << std::llround(n) << "\n" << n;
G.M.
  • 12,232
  • 2
  • 15
  • 18