Sponsored Content
Full Discussion: Decimal field round of
Top Forums Shell Programming and Scripting Decimal field round of Post 302996788 by RudiC on Tuesday 2nd of May 2017 09:34:49 AM
Old 05-02-2017
Would this come close to what you need (admittedly, its the not-requested awk, but it shows the principle)?
Code:
awk '{for (i=6; i<=NF; i++) if ($i+0 == $i) $i+=0} 1' FS="," OFS="," CONVFMT="%.2f" file
26200000,1,14771,12/31/2016,N,3.54,0.84,-1.24,4.21,,,,,,,,,,,4.64,,,,,,,,,4.64,XXXX,02/09/2017,,,,,,,,,A,XX,10463.58

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

incremental addition of hex decimal number in one field

Hi I want to incremental add hex decimal number to a particula field in file eg: addr =123 dept1=0 addr = 345 dept2 =1 addr2 = 124 dept3 =2 . . . . . . addr3 =567 dept15 =f Is there any command which add... (8 Replies)
Discussion started by: diddi_linux
8 Replies

2. Shell Programming and Scripting

Round off the a Decimal value.

HI, I have a script which is used to calculate the Memory & CPU utilization a server. memx=`ssh -l siebel1 ${f} /usr/sbin/prtconf|grep -i 'Memory size'|tr -s " "|/usr/xpg4/bin/awk -F" " '{print $3 * 1024}'` v5=`ssh -l siebel1 ${f} vmstat 1 2 | tail -1 | tr -s " " | /usr/xpg4/bin/awk -v... (3 Replies)
Discussion started by: dear_abhi2007
3 Replies

3. 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

4. Shell Programming and Scripting

need to convert a decimal value to an ascii char with awk for the field delimiter

Hello, I need an awk script to receive a variable that's an decimal value such as 009 or 031 and then convert this value to an ascii character to use as the FS (field separator for the input file). For example, 009 should be converted to an ascii tab 031 should be converted to an ascii... (1 Reply)
Discussion started by: script_op2a
1 Replies

5. Shell Programming and Scripting

To remove decimal values from the field

Hi Friends, Hi Friends, I have a file in the following format file.txt 1|jHDJ|1345.0000000|384837843|39084938 2|jkaehjk|5784.00000|jhejhwej|3398934 i want to remove the 3rd field data decimal points from all lines output.txt 1|jHDJ|1345|384837843|39084938... (5 Replies)
Discussion started by: i150371485
5 Replies

6. Shell Programming and Scripting

How to round up value upto 2 decimal places using sed?

Please help me in rounding up value upto 2 decimal palces using sed command #!/usr/bin/bash a=15.42 b=13.33 c=`echo $a*$b |bc -l` echo $c above code is is giving output "205.5486" but i want the output as "205.55" Thank you... (15 Replies)
Discussion started by: ranabhavish
15 Replies

7. Shell Programming and Scripting

Help with Round Up with 2 decimal point at specific column

Input file: USA 20.5683 UK 3.54221 Japan 2.54001 China 2.50897 Germany 2.05816 . . Desired output file: USA 20.57 UK 3.54 Japan 2.54 China 2.51 Germany 2.06 . . (2 Replies)
Discussion started by: perl_beginner
2 Replies

8. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies
fe_dec_setround(3M)													       fe_dec_setround(3M)

NAME
fe_dec_setround() - set decimal floating-point rounding direction mode SYNOPSIS
DESCRIPTION
The function establishes the decimal rounding direction represented by its argument round. The round argument must equal one of the macros (defined in and If the argument does not match a decimal rounding direction macro, the decimal rounding direction is not changed. The default decimal rounding direction mode is round to nearest with half-way cases away from zero These math functions are supported for HP-UX 11i Version 3 September 2008 Update and forward. USAGE
To use this function, compile with the option. Make sure your program defines and then includes Specify on the compiler command line or place the call to this function under the effect of an affirmative pragma: If the pragma is placed outside of any top-level declarations in a file, the pragma will apply until another pragma is encountered or until the end of the file is reached. If the pragma is placed at the beginning of a block (compound statement), the pragma will apply until another pragma is encountered or until the end of the block is reached. Link in the math library by specifying or on the linking command line. For more information, see the at the following site: RETURN VALUE
The function returns a zero value if and only if the argument is equal to a decimal rounding direction macro. SEE ALSO
fe_dec_getround(3M), fenv(5). STANDARDS CONFORMANCE
This function conforms to ISO/IEC TR 24732, "Extension for the programming language C to support decimal floating-point arithmetic". fe_dec_setround(3M)
All times are GMT -4. The time now is 01:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy