在C ++中有trunc函数吗?

编程入门 行业动态 更新时间:2024-10-28 04:18:15
本文介绍了在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函数吗?

本文发布于:2023-10-23 04:18:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   函数   trunc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!