Thread: Modulo on decimal numbers

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    39

    Modulo on decimal numbers

    How can I perform modulo on a decimal calculations?

    ie,

    3.01 % 3.00

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Maybe this is what you want:
    Code:
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main ( )
    {
    	double x, y, z;
    	int t;
    	
    	x = 3.5;
    	y = 2.6;
    	z = x / y;
    	t = floor ( z );
    	cout<< "mod is: "<< z-t;
    
    	return 0;
    }
    Although I wouldn't say that is modulo...

    - Micko
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    modf(), in math.h

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    39
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. hex to binary,hex to decimal
    By groovy in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 02:14 AM
  3. Confused by expression.
    By Hulag in forum C Programming
    Replies: 3
    Last Post: 04-07-2005, 07:52 AM
  4. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  5. Help needed with VERY large numbers.
    By jwarner in forum C++ Programming
    Replies: 4
    Last Post: 01-18-2004, 12:01 PM