1. ## floating point value

heyas,

i was wondering if theres a way to determind if a float has a decimal value?

i.e i might have the following times

24:00
09:00
14:30

i want to know if i can iterate through an array or any collection and test if the '.30' exists.

or even more simply a function like isDecimal()

tia

-twans 2. my appologies,

24.00
09.00
14.30

as im storing them as floats! :P 3. If the number minus the floor of the number is anything other than zero, then there are values stored after the decimal place. 4. The only thing I can think of, is to subtract .30 from the number, and then use the modulus operator with a 1. If it was n.30, your answer will be 1.

Remember though, that floating point values can never be trusted to be exact, so don't use the == operator to test if it's 1. You could find the absolute value of (1 - yourNumber), and then test to see if that number is less then .1 or something. 5. works a charm,

those that are interested
Code:
```#include <cmath>

floor(float);```

-twan

[edit: silly typo on the include] 6. You're welcome.

The standard library function floor() is in <cmath>. What is <floor>? 7. can the modulus operator be used on floats?

-thanks for the reply too sean. 8. Modulus only works on ints I believe.

You could get dirty and cast to int and back to float... something like this:

Code:
```float x = 3.2f;
bool hasDecimal = x != (float)((int)x);```
Note: this code hasn't been tested, I just wanted to get the idea across  9. There's an fmod(float x, float y) function in <cmath> that returns the remainder of x/y. 10. Originally Posted by twans
can the modulus operator be used on floats?

-thanks for the reply too sean.
Use the fmod function to calculate modulus on floating-point values.

Darn... beaten! [/edit] Popular pages Recent additions 