?
Solved

how to find the modulus of flaot values

Posted on 2012-04-01
5
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 35

Accepted Solution

by:
sarabande earned 1500 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 35

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

718 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