03-26-2009
Rounding off decimals to the nearest number in PERL
Hi Guys,
I am generating a statistical report , below is the snippet of the code :
Quote:
$sliceStartTime = &convertTime($sTime);
$sliceEndTime = &convertTime($eTime);
$totalTime = $sliceEndTime - $sliceStartTime;
$nSlices = $totalTime / ($slice * 60);
Now, $nSlices stands for the time duration,meaning,the statistics will be displayed for that particular time duration. Trouble is, for certain values of $totalTime (which is the end time - start time ), i end up getting decimal values for $nSlices. I am coding this in PERL, and i wish i could find a way to round off the decimals to the nearest whole number. For example, if the value of $nSlices is 23.323232 i would like to round it off to 23, and if the value of $nSlices is 23.7878787 i would like to round it off to 24. Basically,anything over .5 and above gets rounded off to the next whole number, and anything below .5 gets rounded off to the previous number. Anyways that i can achieve this? Help would be much appreciated!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello,
I searched a lot on this Forum.
Please help me with the below problem.
I want to divide two numbers and the result should be the next nearest whole number.
E.G. Dividing 10.8/5 ideally gives 2.16. But the result should be 3 i.e. rounded off to the next whole number.
Any help will... (2 Replies)
Discussion started by: damansingh
2 Replies
2. Shell Programming and Scripting
Hi Experts,
I have a command that gives me the output as below
root@ckpgpay11core> cat sara | awk '{ sum += $1} ; END { print sum }' | awk {'print $1/90'}
8.88889
how do i remove the decimal spaces so that the figure will round itself to 9?
Thanks. (3 Replies)
Discussion started by: aismann
3 Replies
3. Shell Programming and Scripting
Hi,
I am trying to find if there is a way to convert regular decimal values to Paced decimal values. I tried to find a c program but I could get a Packed converted to regular decimal not the other way round.
If not unix please let me know if any other progrimming language I can use to do... (2 Replies)
Discussion started by: mgirinath
2 Replies
4. Shell Programming and Scripting
Is there a way I can round time in perl to the nearest five minutes?
For example if I have log giving the following time stamps
23,52,30 it would rounded up to 23,55,00
and
23,50,01 would be rounded to 23,50,00 (3 Replies)
Discussion started by: borderblaster
3 Replies
5. Shell Programming and Scripting
It seems that perl sprintf uses the round-to-even method:
foreach my $i ( 0.5, 1.5, 2.5, 3.5 ) {
printf "$i -> %.0f\n", $i;
}
__END__
0.5 -> 0
1.5 -> 2
2.5 -> 2
3.5 -> 4
4.5 -> 4
Where we probably wants to use round-half-up, i.e. output should be as below:
0.5 -> 1
1.5 -> 2... (8 Replies)
Discussion started by: ganapati
8 Replies
6. Shell Programming and Scripting
Hello Guys,
I'm very new on here and require some help matching up and printing some columns using awk.
I have two text files. The first file has Longitude data in column 1 (lon.txt) and the second one (node.txt) has again another Longitude data in column 1 (not exact as the first one) + in... (7 Replies)
Discussion started by: ian_gooch
7 Replies
7. Shell Programming and Scripting
Dear Experts,
I'm trying to find a way to round a number but in this way:
14367.577 ---> 14000
I used the following to round the number to the closer integer:
echo $var|awk '{print int($1+0.5)}'
and also:
xargs printf "%1.0f"
However, they don't work for my above... (9 Replies)
Discussion started by: Gery
9 Replies
8. UNIX for Dummies Questions & Answers
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
9. Shell Programming and Scripting
I have a number, which I want to convert into the nearest floating number upto two places after the decimal point.
E.g.
1.2346 will become 1.23
but
1.2356 will become 1.24 .
Similarly
0.009 will be 0.01
and
0.001 will be 0.00 or 0.0 (not 0, wnat to keep the decimal... (1 Reply)
Discussion started by: hbar
1 Replies
10. Shell Programming and Scripting
Heyas
Trying to calculate the total size of a file by reading its bitrate.
Code snippet:
fs_expected() { #
# Returns the expected filesize in bytes
#
pr_str() {
ff=$(cat $TMP.info)
d="${ff#*bitrate: }"
echo "${d%%,*}" | $AWK '{print $1}' | head -n 1
}
t_BYTERATE=$((... (9 Replies)
Discussion started by: sea
9 Replies
LEARN ABOUT DEBIAN
sylseg-sk-training
sylseg-sk-training(1) USER COMMANDS sylseg-sk-training(1)
NAME
sylseg-sk-training - train the statistic for the syllabic segmentation
SYNOPSIS
sylseg-sk-training [--color] [--dl debug level] [--help] [<input file>]
DESCRIPTION
The sylabic segmentation is esential for some linguistic or speech recognition applications. Depending on the language either rule based or
statistical approach is beying used. For Slovak the statistical approach seems to be more suitable.
sylseg-sk-training creates the necessary data for one of the statistical approaches for the syllabic segmentaion. The input data are
expected to be word segmented into syllables. The syllabic separator should be "-". If no input file is specified, the standard input is
expected. The output is written in to the file. The filename is input filename with the extension ".statistics". If standard input is
used, then the output filename is syl_output.statistics.
The design of the sylseg-sk-training is language independent. Theoretically it should work for any language.
OPTIONS
--color
Enable color output.
--dl Set the debug level. Control the amount of displayed information The debug level 0 displays nothing. The maximum level 5 displays
full debugging report. The default debug level is 1.
--help display a short help text
EXAMPLES
Use file aaa.txt as training input and set up debug level to 3:
sylseg-sk-training --dl 3 aaa.txt
EXIT STATUS
sylseg-sk-training returns a zero if the training succeeds
AUTHOR
Jozef Ivanecky (dodo (at) kanoistika.sk)
SEE ALSO
sylseg-sk(1)
version 0.4 September 9, 2006 sylseg-sk-training(1)