Math.h Help

This is a discussion on Math.h Help within the C Programming forums, part of the General Programming Boards category; There's a command in Math.h in C to round-up numbers. What's the name of that command? For example of Rounding-up ...

  1. #1
    blueXrogue
    Guest

    Question Math.h Help

    There's a command in Math.h in C to round-up numbers. What's the name of that command? For example of Rounding-up numbers is.

    Round up 5.5 which is, 6 is the answer.

    Thanks in advance.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    There's different ceiling functions, depending on what you want to do:

    double ceil(double x);
    float ceil(float x); [C++ only]
    long double ceil(long double x); [C++ only]
    float ceilf(float x); [required with C99]
    long double ceill(long double x); [required with C99]

  3. #3
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Code:
    #include<iostream>
    
    float Round(float number)
    {
    	float f_temp = number * 10.0;
    	int i_decimal = (int) f_temp % 10;
    	if( i_decimal >= 5) 
    	{
    		i_decimal = (int) number +1;
    	}else
    	{
    		i_decimal = (int) number;
    	}
    	return i_decimal;
    }
    
    int main()
    {
    
    	std::cout << Round(7.5);
    	return 0;
    }
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. math.h
    By tsutharssan in forum C Programming
    Replies: 3
    Last Post: 07-03-2009, 03:24 PM
  2. Trig Functions without math.h
    By daltore in forum C Programming
    Replies: 13
    Last Post: 12-29-2008, 04:47 PM
  3. cosine series with out using math.h
    By indrajit_muk in forum C Programming
    Replies: 5
    Last Post: 12-16-2008, 08:17 PM
  4. undefined reference to `sqrt' when using math.h
    By Milhas in forum C Programming
    Replies: 4
    Last Post: 03-31-2008, 07:11 PM
  5. using round from math.h
    By axr0284 in forum C Programming
    Replies: 5
    Last Post: 05-02-2006, 12:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21