I have 32 GB RAM. The variable ram_in_gb
returns 31.917182922363281. I want to round it to 31.9. I expect the buffer
to return 31.9 GB
string. There was an easy way to do that using wvprintf
, sprintf
or something like that. I don't remember how I used to do it in the past, so here is my question.
// Usage
wchar_t ram[64]{};
get_ram(ram);
bool get_ram(LPWSTR buffer)
{
auto memory_status{ MEMORYSTATUSEX {} };
memory_status.dwLength = sizeof MEMORYSTATUSEX;
const auto result = GlobalMemoryStatusEx(&memory_status);
if (result)
{
auto ram_in_gb = static_cast<double>(memory_status.ullTotalPhys) / (1024 * 1024 * 1024);
wcscpy(buffer, );
}
return result;
}