Solved

how to find the modulus of flaot values

Posted on 2012-04-01
5
196 Views
Last Modified: 2012-07-05
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.
0
Comment
Question by:nagaharikola
5 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 37792918
You may use fmod(result/1000.0)
0
 

Author Comment

by:nagaharikola
ID: 37792938
i cannot use library function.
is there any other way to do this
0
 
LVL 84

Expert Comment

by:ozo
ID: 37793817
what functions can you use?
0
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 37796936
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
 
LVL 33

Expert Comment

by:sarabande
ID: 38155209
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

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question