Sponsored Content
Top Forums UNIX for Dummies Questions & Answers converting string to number in shell script Post 302600850 by itkamaraj on Wednesday 22nd of February 2012 08:57:56 AM
Old 02-22-2012
Code:
$ echo "0 + `awk '/Run time/ {print $7}' idsOutput`" | bc
1.3579
$ echo "10 + `awk '/Run time/ {print $7}' idsOutput`" | bc
11.3579

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell to number and to string

Hello Does the unix korn shell provide a function to convert between number and string data-types regards Hrishy (1 Reply)
Discussion started by: xiamin
1 Replies

2. Shell Programming and Scripting

need help converting string to number for calculation

I've searched the forum and google, but can't see an answer to this simple problem. Here's my small test script: #!/bin/csh echo "enter a number:" read num echo "you entered $num" set num = `expr $num + 1` echo new value is $num can someone show me how to do this calculation? note that... (4 Replies)
Discussion started by: tpatput
4 Replies

3. Shell Programming and Scripting

Converting Shell Script to HTML

Hi, Im new to shell scripting. My task is to convert shell script feed into html, so basically I have a lot of information in shell script and I want to convert it html. I know you can simply convert the information by hand, but is there any simpler way? Thank you Dave (3 Replies)
Discussion started by: davwel
3 Replies

4. Shell Programming and Scripting

Problem in converting number in shell script

Hi All, I am writing a shell script in which I want to convert a number like : Suppose the number is "98487657" and we have to convert it to "98000000", what I want to do is to retain first 2 digits and convert all remaining digits to "0". Number could be of any length (length... (4 Replies)
Discussion started by: amitanshu.verma
4 Replies

5. Shell Programming and Scripting

How to Check given string is number in shell script?

Hi, Can anyone help me out to check whether the input argument is number? Example: REQUEST_ID="123456" I need to check the REQUEST_ID value is number or string. Thanks in Advance Regards BS (6 Replies)
Discussion started by: balajiora
6 Replies

6. Shell Programming and Scripting

Shell Script to identify the line number containing a particular "string"

Hi, I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file. And then copy 200 lines above that line number to a new file. Can someone provide pointers on how to write this script or what command to be used ? Any... (2 Replies)
Discussion started by: kk2202
2 Replies

7. Shell Programming and Scripting

Unix shell script converting temperatures.

:confused:Please I really need help with an assignment question. I need to write a script that will take the input from a file and convert the number from Centigrade(Celcius) to Fahrenheit or vice versa. Thank you so much. I really need it to be detailed. Please remember the input comes from a file. (1 Reply)
Discussion started by: starter101
1 Replies

8. Shell Programming and Scripting

Converting rows to columns using shell script

I have a script which converts rows to columns. file_name=$1 mailid=$2 #CREATE BACKUP OF ORIGINAL FILE #cp ${file_name}.xlsx ${file_name}_temp.xlsx #tr '\t' '|' < ${file_name}_temp.xlsx > ${file_name}_temp.csv #rm ${file_name}_temp.xlsx pivot_row=`head -1 ${file_name}` sed 1d... (3 Replies)
Discussion started by: andy538
3 Replies

9. Shell Programming and Scripting

Converting a shell script to program

Hi I am new in programming. I have written a shell code, but i want to secure my code. I have tried SHC. It is converting it to binary, but can be converted in plain text again by core dump. I have tried to convert it in rpm by "rpmbuild -bb my.spec" option but the result is same. ... (4 Replies)
Discussion started by: Priy
4 Replies

10. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies
ROUND(3)								 1								  ROUND(3)

round - Rounds a float

SYNOPSIS
float round (float $val, [int $precision], [int $mode = PHP_ROUND_HALF_UP]) DESCRIPTION
Returns the rounded value of $val to specified $precision (number of digits after the decimal point). $precision can also be negative or zero (default). Note PHP doesn't handle strings like "12,300.2" correctly by default. See converting from strings. PARAMETERS
o $val - The value to round o $precision - The optional number of decimal digits to round to. o $mode - Use one of the following constants to specify the mode in which rounding occurs. +--------------------+---------------------------------------------------+ | Constant | | | | | | | Description | | | | +--------------------+---------------------------------------------------+ | | | | PHP_ROUND_HALF_UP | | | | | | | Round $val up to $precision decimal places away | | | from zero, when it is half way there. Making 1.5 | | | into 2 and -1.5 into -2. | | | | | | | |PHP_ROUND_HALF_DOWN | | | | | | | Round $val down to $precision decimal places | | | towards zero, when it is half way there. Making | | | 1.5 into 1 and -1.5 into -1. | | | | | | | |PHP_ROUND_HALF_EVEN | | | | | | | Round $val to $precision decimal places towards | | | the next even value. | | | | | | | |PHP_ROUND_HALF_ODD | | | | | | | Round $val to $precision decimal places towards | | | the next odd value. | | | | +--------------------+---------------------------------------------------+ RETURN VALUES
The rounded value EXAMPLES
Example #1 round(3) examples <?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?> Example #2 $mode examples <?php echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10 echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9 echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10 echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9 echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9 echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9 ?> Example #3 $mode with precision examples <?php /* Using PHP_ROUND_HALF_UP with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_UP); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_UP); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_UP); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_UP); // -1.5 /* Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_DOWN); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_DOWN); // -1.5 /* Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_EVEN); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_EVEN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_EVEN); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_EVEN); // -1.5 /* Using PHP_ROUND_HALF_ODD with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_ODD); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_ODD); // -1.5 ?> CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The $mode parameter was introduced. | | | | | 5.2.7 | | | | | | | The inner workings of round(3) was changed to | | | conform to the C99 standard. | | | | +--------+---------------------------------------------------+ SEE ALSO
ceil(3), floor(3), number_format(3). PHP Documentation Group ROUND(3)
All times are GMT -4. The time now is 07:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy