Search code examples
c++doubleroundingscientific-notation

Print double without scientific format & rounded to nearest integer


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


Solution

  • 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;