gpt4 book ai didi

c++ - 检查变量是C++中的整数还是 float

转载 作者:行者123 更新时间:2023-11-30 05:21:04 26 4
gpt4 key购买 nike

C++中如何判断初始化的变量是整数值还是 float ?

示例代码块如下所示:

int main()
{
double number = 9.99;

if (/*Checks whether the value of the 'number' is an integral*/)
cout << "The 'number' has an integral value";
else
cout << "It's not an integral value" // This condition will true if 'number' has a floating point number
return 0;

}

最佳答案

您正在寻找 fmod(number, 1.0)。当且仅当这恰好 0.0(这里没有 epsilon)时,number 是一个整数值。

关于c++ - 检查变量是C++中的整数还是 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40402853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com