Solved

how to find the modulus of flaot values

Posted on 2012-04-01
5
192 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 32

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 32

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now