Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在制作一个 IOS 计算器应用程序。我想知道两个数字的除法是否会给出一个浮点值或一个 int 值。任何人都可以告诉我如何得到这个吗?
谢谢。
如果您想知道而不实际计算 a/b,请检查 a/b 的其余部分是否为空:
if (fmod(a,b) == 0) { // integer result } else { // floating-point result }
见http://www.cplusplus.com/reference/cmath/fmod/
如果floor()一个数的 等于那个数,它就是一个整数。
floor()
但是,请注意浮点 陷阱。