## Bash Rounding to 2 decimal places

Bash Rounding to 2 decimal places
# 1
03-10-2013
Bash Rounding to 2 decimal places

I have a number in a bash variable n, and want to round it to 2 decimal places. How can I do that?

Need to have
 kristinu View Public Profile for kristinu Find all posts by kristinu
# 2
03-10-2013
Try:

These 3 Users Gave Thanks to Chubler_XL For This Post:
 Chubler_XL View Public Profile for Chubler_XL Find all posts by Chubler_XL

Test Your Knowledge in Computers #291
Difficulty: Easy
In August 2016, the United States government announced a new federal source-code policy. This policy mandates that at least 50% of custom source code developed by or for any agency of the federal government must be released as open-source software (OSS).
True or False?

## Sum the fields with 6 decimal places - getting only 2 decimal places as output

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

## Rounding off a decimal

How to round off a decimal number to higher whole number using ceil command in unix? Eg. 4.41 or 4.11 or 4.51 should be rounded off to 5.

## Rounding decimal values in a column

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

## Rounding off decimal values

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

## Arithmetic but keep 2 decimal places

I am trying to perform arithmetric, for example, to increment the value of variable \$a (say 3) by 0.05 but when I tried the following expression let a=a+0.05 or a=\$((a+0.05)) both returned 3.0499999999999998 I want to keep 2 decimal places so it returns 3.05 instead.

## Decimal places

i need to multiplay a number with 1.00.. so that the output should contain two decimal places at end.. for example... 236 * 1.00 = 236.00 245.8 * 1.00 = 245.80 but when i perform multiplication it shows output as. 236 245.8 can anyone help me to get the actual output of...

## Four decimal places with awk

i have a script in which awk prints "(\$2-1700)/10000" and the answer is -0.07,but i want the answer in 4 decimal places. that is -0.0700. How can i sue awk to get my results in four decimal places

## Rounding a decimal

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

## trimm up the decimal places in output

I have a perl script that reports the avg time of a application call and the total number of calls. This works fine, however I would like to trim the number of decimal places reported from 12 to like 3 and I don't know how. Any suggestions? Here is what I use to get the avg time... for \$eRef (...