__int64 TotalNumberOfBytes; BOOL GetDiskFreeSpaceFlag = GetDiskFreeSpaceEx( L"c:\\", // directory name NULL, // bytes available to caller (PULARGE_INTEGER)&TotalNumberOfBytes, // bytes on disk NULL // free bytes on disk ); if (GetDiskFreeSpaceFlag != 0) { printf("\n\rОбщий объем: %I64d ( %I64d Mb )", TotalNumberOfBytes, TotalNumberOfBytes / 1024 / 1000); } else printf("Отсутствует (GetDiskFreeSpace)"); 

Displays:

Total amount: 249464614912 (243617 Mb)

I want to do:

Total amount: 249 464 614 912 (243617 Mb)

I would like to display with spaces between digits, since there are displayed large numbers, for convenience, I want that would be displayed one by one. How to do this?
It is written that you need to use exactly this __int64 (64-bit) type to work with such large numbers.

  • How would you display a 32-bit number in groups of three decimal digits? ULONGLONG use an unsigned type such as ULONGLONG - jfs
  • one
    Related question: Print integer with separators - jfs

1 answer 1

You can configure numpunct.thousands_sep :

 #include <cstdint> #include <iostream> #include <locale> struct space_out : std::numpunct<char> { char do_thousands_sep() const { return ' '; } // separate with spaces std::string do_grouping() const { return "\3"; } // groups of 3 digit }; int main() { uint64_t u = 249464614912; std::cout << "default locale: " << u << '\n'; std::cout.imbue(std::locale(std::cout.getloc(), new space_out)); std::cout << "locale with modified numpunct: " << u << '\n'; } 

Example:

 $ c++ -std=c++11 *.cc && ./a.out default locale: 249464614912 locale with modified numpunct: 249 464 614 912