Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

round(3) [freebsd man page]

ROUND(3)						   BSD Library Functions Manual 						  ROUND(3)

NAME
round, roundf, roundl -- round to nearest integral value LIBRARY
Math Library (libm, -lm) SYNOPSIS
#include <math.h> double round(double x); float roundf(float x); long double roundl(long double x); DESCRIPTION
The round(), roundf(), and roundl() functions return the nearest integral value to x; if x lies halfway between two integral values, then these functions return the integral value with the larger absolute value (i.e., they round away from zero). SEE ALSO
ceil(3), floor(3), ieee(3), lrint(3), lround(3), math(3), rint(3), trunc(3) STANDARDS
These functions conform to ISO/IEC 9899:1999 (``ISO C99''). HISTORY
The round() and roundf() functions appeared in FreeBSD 5.3. The roundl() function appeared in FreeBSD 6.0. BSD
April 7, 2005 BSD

Check Out this Related Man Page

ROUND(3)						     Linux Programmer's Manual							  ROUND(3)

NAME
round, roundf, roundl - round to nearest integer, away from zero SYNOPSIS
#include <math.h> double round(double x); float roundf(float x); long double roundl(long double x); Link with -lm. Feature Test Macro Requirements for glibc (see feature_test_macros(7)): round(), roundf(), roundl(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L; or cc -std=c99 DESCRIPTION
These functions round x to the nearest integer, but round halfway cases away from zero (regardless of the current rounding direction, see fenv(3)), instead of to the nearest even integer like rint(3). For example, round(0.5) is 1.0, and round(-0.5) is -1.0. RETURN VALUE
These functions return the rounded integer value. If x is integral, +0, -0, NaN, or infinite, x itself is returned. ERRORS
No errors occur. POSIX.1-2001 documents a range error for overflows, but see NOTES. VERSIONS
These functions first appeared in glibc in version 2.1. ATTRIBUTES
Multithreading (see pthreads(7)) The round(), roundf(), and roundl() functions are thread-safe. CONFORMING TO
C99, POSIX.1-2001. NOTES
POSIX.1-2001 contains text about overflow (which might set errno to ERANGE, or raise an FE_OVERFLOW exception). In practice, the result cannot overflow on any current machine, so this error-handling stuff is just nonsense. (More precisely, overflow can happen only when the maximum value of the exponent is smaller than the number of mantissa bits. For the IEEE-754 standard 32-bit and 64-bit floating-point num- bers the maximum value of the exponent is 128 (respectively, 1024), and the number of mantissa bits is 24 (respectively, 53).) If you want to store the rounded value in an integer type, you probably want to use one of the functions described in lround(3) instead. SEE ALSO
ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2013-06-21 ROUND(3)
Man Page

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to round a value

Hello, In a unix shell script,i want to round a variabele to a nearest number Ex: set count=104.4 How can i round that to 105.? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies

2. Shell Programming and Scripting

round in KSH

Is there an easy way to round a number up in Korn shell? ie. 10.4 --> 11 Thanks. (6 Replies)
Discussion started by: here2learn
6 Replies

3. Shell Programming and Scripting

round a number

In a shell script - How do I round a decimal number (contained in a variable) to the nearest whole number? (2 Replies)
Discussion started by: achieve
2 Replies

4. UNIX for Advanced & Expert Users

Help In Awk

Hi Friends, I need a help again in awk. I just need to round up a value. Eg Say x=5.664584525 I need to display x=5.66 means round. How can i do round in UNIX. (6 Replies)
Discussion started by: Soumya Dash
6 Replies

5. Shell Programming and Scripting

How to round up on fives in unix?

i'm a newbie here, i need help with a shell script. for a given number, if it is greater than ten round to the nearest 10 same for 100, if it is greater than 100 round to the nearest 100, and same for 1000. i'm confused how to start this... its supposed to look like this input ... (11 Replies)
Discussion started by: CRAZYLITTLELOU
11 Replies

6. Shell Programming and Scripting

round decimal values and use in loops

i have a file in which 3 values are stored like --4.72 4.42 3.86 what i wanna do is that take read each value and compare with a fixed value say 5 but cant do so as i am getting an error for the same. please check the code cat /home/nsadm/auto/Logging/uptime.txt| while read a b c do if... (2 Replies)
Discussion started by: gemnian.g
2 Replies

7. Shell Programming and Scripting

Using sed to round a number

Hey everyone, I was wondering if i am able to write a sed command to round a number to two decimal places. So for example: 1.58674 would be 1.58 I just want to chop off the numbers to the right of the second digit after the period. I know this is probably trivial but the closest i got was... (8 Replies)
Discussion started by: GmGeubt
8 Replies

8. UNIX for Dummies Questions & Answers

Rounding up to nearest whole number

Hi all of you, Would be great if you help me with how to round up to whole number from my input values like 2.99996,2.17890,3.00002,-2.3456,-2.7890 o/p should be like 3,2,3,-2,-3 thnks in adv!!!! regards (3 Replies)
Discussion started by: Indra2011
3 Replies