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の電卓アプリを作っています。2 つの数値の除算が float 値または int 値のどちらになるかを取得したいと考えています。これを取得する方法を教えてもらえますか?
ありがとう。
実際に a/b を計算せずに知りたい場合は、a/b の残りが null かどうかを確認します。
if (fmod(a,b) == 0) { // integer result } else { // floating-point result }
http://www.cplusplus.com/reference/cmath/fmod/を参照してください。
数値の がその数値と等しい場合floor()、それは整数です。
floor()
ただし、浮動小数点の 落とし穴には注意してください。