Hi Pavan.
No need for complicated matters.
#include<iostream>
#include<cmath>
int main()
{
int x = 3.67;
double n;
n = (int)round(x + 0.5); // For casting // For casting/truncation reasons, add 0.5
std::cout << n << std::endl;
return 0;
}
The snippet above returns: 4.
Please, see: http://ideone.com/iYSaVo
Best,
Édouard
5. rounding in quantlib (Pavan Shah)
Hello,
I am trying to round time to expiry using quantlib.
How do i round a double to an int?
i know i could force type conversion in c++ but that will round a 3.67 to 3 I believe.
i don't want that.
Can someone provide an example please with the proper class and method?
thanks
Pavan
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users