Discussion Locked

Rounding

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Can anyone give me some techniques for rounding numbers in C++. The numbers are being stored as exponential expressions.

3 replies

by rdgates

most programming languages have built in routines for simple math functions like rounding. The problem is the rounded product might not be the data type you are looking for ie. integer, double, float. Sometimes to get the decimal places that you want, it is necessary to multiply by 100 (for 2 decimal places), do your rounding, then divide by 100. You can change that to get the number of decimal places you are looking for. Keep in mind, that you may need to type cast the variables to get the correct output.

This discussion is closed to new replies.