There is a ceil() function in C, but there is no utility named ceil. But, you can perform the equivalent functionality in a 1993 or later version of ksh or with awk.
Unfortunately, the code suggested by RavinderSingh13 won't work for integral values (even though it works perfectly for non-integral values).
The following should work correctly when given integral or floating point values for values into an integral value of type long integer:
which produces the output:
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
Last edited by Don Cragun; 01-16-2015 at 06:06 AM..
Reason: Add note for Solaris users.
This User Gave Thanks to Don Cragun For This Post:
Hi,
I am currently using tcsh
I am trying to round a decimal number to the ten-thousandths place
For instance:
1.23456 is rounded up towards 1.2346
I am not looking for truncation, but for rounding. Anyone know how to do this with awk or expr?
Thanks (2 Replies)
Anybody please help me...
Design an algorithm that accepts an input a decimal number and converts it into BCD (Binary Coded Decimal) representation. Also, draw its Flow Chart.
This is a unix qn...
plz post algorithm for that :confused: (1 Reply)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Design an algorithm that accepts an input a decimal number and converts it into BCD (Binary... (2 Replies)
Hi Friends,
This is my last post for today.
My input file is
chr1 100 200
chr1 123 300
chr1 300 400
chr1 420 520
chr10 132344343 132348674
When I try using this command
awk '{v=($3+$2)/2; print $0"\t"v}' 1
This is my output
chr1 100 200 150
chr1 123 300 211.5 (2 Replies)
Hi,
I wanted to round all the values in a column to nearest integer. I have multiple files with only two columns and I want to round values in column 2. e.g
input_file
A1 23.971578 A2 34.624976 A3 46.403446 A4 375 A5 1 A6 3 A7 ... (3 Replies)
Hi,
I want to convert two hexadecimal numbers to decimal using unix command line.
1cce446295197a9d6352f9f223a9b698
fc8f99ac06e88c4faf669cf366f60d
I tried using
`echo "ibase=16; $no |bc`
printf '%x\n' "1cce446295197a9d6352f9f223a9b698"
but it doesn't work for such big number it... (4 Replies)
Hi ,
seq can be 0...128
int windex = seq / 8;
int bindex = seq % 8;
unsigned char bitvalue = '\x01' << (7-bindex) ;
bpv.bitmapvalue = bitvalue;
This is the part of a program to convert decimal to bitmap value of hexadecimal.
I want this to change to convert only to... (1 Reply)
I used the below script to Sum up a field in a file based on some unique values. But the problem is when it is summing up the units, it is truncating to 2 decimals and not 6 decimals as in the input file (Input file has the units with up to 6 Decimals – Sample data below, when the units in the 2... (4 Replies)
Discussion started by: brlsubbu
4 Replies
LEARN ABOUT SUSE
llroundf
LROUND(3) Linux Programmer's Manual LROUND(3)NAME
lround, lroundf, lroundl, llround, llroundf, llroundl - round to nearest integer, away from zero
SYNOPSIS
#include <math.h>
long int lround(double x);
long int lroundf(float x);
long int lroundl(long double x);
long long int llround(double x);
long long int llroundf(float x);
long long int llroundl(long double x);
Link with -lm.
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
All functions shown above: _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc -std=c99
DESCRIPTION
These functions round their argument to the nearest integer value, rounding away from zero, regardless of the current rounding direction
(see fenv(3)).
Note that unlike round(3), ceil(3), etc., the return type of these functions differs from that of their arguments.
RETURN VALUE
These functions return the rounded integer value.
If x is a NaN or an infinity, or the rounded value is too large to be stored in a long (long long in the case of the ll* functions) then a
domain error occurs, and the return value is unspecified.
ERRORS
See math_error(7) for information on how to determine whether an error has occurred when calling these functions.
The following errors can occur:
Domain error: x is a NaN or infinite, or the rounded value is too large
An invalid floating-point exception (FE_INVALID) is raised.
These functions do not set errno.
VERSIONS
These functions first appeared in glibc in version 2.1.
CONFORMING TO
C99, POSIX.1-2001.
SEE ALSO ceil(3), floor(3), lrint(3), nearbyint(3), rint(3), round(3)COLOPHON
This page is part of release 3.25 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/.
2008-08-11 LROUND(3)