Link to home
Start Free TrialLog in
Avatar of nagaharikola
nagaharikolaFlag for Afghanistan

asked on

how to find the modulus of flaot values

Hi,
I in my code , at some point i need to find the modulus
float result ;
if result ==.89 then how to find the mod(result/1000).
the compiler is giving error for this operation.
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

You may use fmod(result/1000.0)
Avatar of nagaharikola

ASKER

i cannot use library function.
is there any other way to do this
Avatar of ozo
what functions can you use?
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
be aware that (int)(result/1000.0) is always 0 when abs(result) < 1000.

if result == .89 (as stated in the original post)  and you want .89 as the remainder you would do

remainder = result - (int)result;

Open in new window


if you want 890 for remainder (thousandth) simply multiply (not divide) the remainder by 1000.

Sara