Solved

how to find the modulus of flaot values

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 138
Problem to save 10 166
xamarin c# deserialize Json containing nested object 2 93
How to install SVN Command Line Client? 5 67
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…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

803 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