Hi Everyone,
I am witting a function in C++ for any given number to round upto the
iRoundTo.
Here is the function I have written:
void RoundUpTo(float& Num, int iRoundUpTo)
{
int iRem = 0;
int iNum = ceil(Num); //Taking another variable since Num float variable
errors out in mod operation below.
if(iNum == 0)
return;
iRem = iNum % iRoundUpTo;
int iFactor = iRoundUpTo - iRem;
iNum += iFactor;
Num = (float)iNum;
}
The expected results is something as follows:
121.23, 10 ==> 130.00
121.23, 100 ==> 200.00
121.23, 1000 ==> 1000.00
121.23, 50 ==> 150.00
3, 10 ==> 10.00
3, 100 ==> 100.00
0.00, 10 ==> 0.00
0.00, 100 ==> 0.00
Please do let me know if this makes sense and will be a good code for what I
need to achieve.
Thanks in advance,
Niranjan.