• C

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.
nagaharikolaAsked:
Who is Participating?
 
sarabandeConnect With a Mentor Commented:
you could use

n =  (int)(result/1000.0);
m = result - (n * (result/1000.0))

Open in new window


n and m should be float.

Sara
0
 
Peter KwanAnalyst ProgrammerCommented:
You may use fmod(result/1000.0)
0
 
nagaharikolaAuthor Commented:
i cannot use library function.
is there any other way to do this
0
 
ozoCommented:
what functions can you use?
0
 
sarabandeCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.