C++/Rounding to specified decimal point length
Want to round a double value to certain number of decimal places using Visual C++ 6.0 SP5.
I always display sixteen  decimal places. There does not appear to be a rounding function availble in the SDK for Visual C++ 6.0. At least I could not find it in MSDN library of October 2001, last compatible MSDN release for Visual C++ 6.0.
Are you aware of any rounding techniques that allow control of decimal point length for said compiler ?
Do I need to create my own rounding function ?
Thank you for your time and consideration.
Hello Ray, thank you for the question.
The way to round decimal numbers the easiest is to use some kind of epislilon value, but that can become a complicated and cumbersome process.
The easy way is to set the precision to the desired number of decimal places with cout as such:
// Show the decimal places
// Number of decimal places to show(2, for example)
If you happen to be using the C-style way to print to the console, it is even easier:
printf("Float: %.02f", floatNum);
Specifies 2 decimal places for that example.
I hope this information was helpful.