Solved

how to find the modulus of flaot values

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

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 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Inorder binary search tree 5 178
SQL handling single and double quotes 3 99
C Language combined operators 28 120
c++ getting the first 10 characters of a char* string 11 104
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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

685 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