Re: 5. rounding in quantlib (Pavan Shah)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: 5. rounding in quantlib (Pavan Shah)

tallent_e
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


------------------------------------------------------------------------------
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