在C ++中有trunc函数吗? [英] Is there a trunc function in C++?
本文介绍了在C ++中有trunc函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索过,找不到C ++的 trunc
函数。我知道我可以这样做:
int main()
{
double a = 12.566789;
cout<< setprecision(2)<<固定< (int)(a * 100)/ 100.0 < endl
return 0;
}
但我不确定这是最好的方法。谢谢。 $ <$> $ <$> $ <$ <$> $ <$ <$> $ <$> < cmath> :
#include< iostream&
#include< cmath>
int main(){
std :: cout< trunc(3.141516)<< std :: endl;
}
我想你还在找别的东西?
I searched around and couldn't find the trunc
function for C++. I know I can do this:
int main()
{
double a = 12.566789;
cout << setprecision(2) << fixed << (int)(a * 100) / 100.0 << endl;
return 0;
}
but I'm not sure it's the best way to do this. Thank you.
解决方案
trunc
is there, in <cmath>
:
#include <iostream>
#include <cmath>
int main() {
std::cout << trunc(3.141516) << std::endl;
}
I suppose you're looking for something else?
这篇关于在C ++中有trunc函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文