Sponsored Content
Full Discussion: Decimal places
Top Forums Shell Programming and Scripting Decimal places Post 302516765 by arunmanas on Monday 25th of April 2011 03:27:30 AM
Old 04-25-2011
Decimal places

Excel file look like:

134.4
126.7
144
555
77.88

the required output is

134.40
126.70
144.00
555.00
77.88
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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 (... (2 Replies)
Discussion started by: theninja
2 Replies

2. Shell Programming and Scripting

Using the "Less Than" (-lt) switch on numbers with decimal places?

I'm using shell scripts to run some commands for the Configuration Management tool called Telelogic Synergy. I need to get the script to compare version numbers of files. The version numbers of the files are part of the actual filename, such as the following example: example_file-1... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

3. Shell Programming and Scripting

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 (4 Replies)
Discussion started by: tomjones
4 Replies

4. Shell Programming and Scripting

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. (6 Replies)
Discussion started by: piynik
6 Replies

5. Shell Programming and Scripting

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? n=0.0867268 Need to have num=0.09 (1 Reply)
Discussion started by: kristinu
1 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

Printing with decimal places from last 4 digits

I have input file like below, 201424|9999|OSS|622010|RGT|00378228764 201424|8888|OM|587079|RGT|00284329675 201424|7777|OM|587076|RGT|00128671024 201424|6666|OM|581528|RGT|00113552084 Output should be like below, should add decimal (.) from last 4 digits. ... (2 Replies)
Discussion started by: vinothsekark
2 Replies

8. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: brlsubbu
4 Replies

9. Shell Programming and Scripting

Calculate the constant e to 14+ decimal places using integer maths.

Hi guys... I am loving this integer maths thing. 64 bit systems are certainly easier than 32 bit, but hey, I don't intend to leave out my fav' platform. Using one of the 'Brothers' methods, URL inside the code. #!/bin/sh # # #!/usr/local/bin/dash # e_constant.sh # Brother's formula . #... (2 Replies)
Discussion started by: wisecracker
2 Replies
Decimal(3tcl)						  Tcl Decimal Arithmetic Library					     Decimal(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
::Decimal - General decimal arithmetic SYNOPSIS
package require Tcl ?8.5? ::Decimal::fromstr string ::Decimal::tostr decimal ::Decimal::setVariable variable setting ::Decimal::add a b ::Decimal::+ a b ::Decimal::subtract a b ::Decimal::- a b ::Decimal::multiply a b ::Decimal::* a b ::Decimal::divide a b ::Decimal::/ a b ::Decimal::divideint a b ::Decimal::remainder a b ::Decimal::abs decimal ::Decimal::compare a b ::Decimal::max a b ::Decimal::maxmag a b ::Decimal::min a b ::Decimal::minmag a b ::Decimal::plus a ::Decimal::minus a ::Decimal::copynegate a ::Decimal::copysign a b ::Decimal::is-signed decimal ::Decimal::is-zero decimal ::Decimal::is-NaN decimal ::Decimal::is-infinite decimal ::Decimal::is-finite decimal ::Decimal::fma a b c ::Decimal::round_half_even decimal digits ::Decimal::round_half_up decimal digits ::Decimal::round_half_down decimal digits ::Decimal::round_down decimal digits ::Decimal::round_up decimal digits ::Decimal::round_floor decimal digits ::Decimal::round_ceiling decimal digits ::Decimal::round_05up decimal digits _________________________________________________________________ DESCRIPTION
The decimal package provides decimal arithmetic support for both limited precision floating point and arbitrary precision floating point. Additionally, integer arithmetic is supported. More information and the specifications on which this package depends can be found on the general decimal arithmetic page at http://speleotrove.com/decimal This package provides for: o A new data type decimal which is represented as a list containing sign, mantissa and exponent. o Arithmetic operations on those decimal numbers such as addition, subtraction, multiplication, etc... Numbers are converted to decimal format using the operation ::Decimal::fromstr. Numbers are converted back to string format using the operation ::Decimal::tostr. EXAMPLES
This section shows some simple examples. Since the purpose of this library is to perform decimal math operations, examples may be the sim- plest way to learn how to work with it and to see the difference between using this package and sticking with expr. Consult the API section of this man page for information about individual procedures. package require decimal # Various operations on two numbers. # We first convert them to decimal format. set a [::Decimal::fromstr 8.2] set b [::Decimal::fromstr .2] # Then we perform our operations. Here we multiply set c [::Decimal::* $a $b] # Finally we convert back to string format for presentation to the user. puts [::Decimal::tostr $c] ; # => will output 8.4 # Other examples # # Subtraction set c [::Decimal::- $a $b] puts [::Decimal::tostr $c] ; # => will output 8.0 # Why bother using this instead of simply expr? puts 8.399999999999999 ; # => will output 8.399999999999999 puts 7.999999999999999 ; # => will output 7.999999999999999 # See http://speleotrove.com/decimal to learn more about why this happens. API
::Decimal::fromstr string Convert string into a decimal. ::Decimal::tostr decimal Convert decimal into a string representing the number in base 10. ::Decimal::setVariable variable setting Sets the variable to setting. Valid variables are: o rounding - Method of rounding to use during rescale. Valid methods are round_half_even, round_half_up, round_half_down, round_down, round_up, round_floor, round_ceiling. o precision - Maximum number of digits allowed in mantissa. o extended - Set to 1 for extended mode. 0 for simplified mode. o maxExponent - Maximum value for the exponent. Defaults to 999. o minExponent - Minimum value for the exponent. Default to -998. ::Decimal::add a b ::Decimal::+ a b Return the sum of the two decimals a and b. ::Decimal::subtract a b ::Decimal::- a b Return the differnece of the two decimals a and b. ::Decimal::multiply a b ::Decimal::* a b Return the product of the two decimals a and b. ::Decimal::divide a b ::Decimal::/ a b Return the quotient of the division between the two decimals a and b. ::Decimal::divideint a b Return a the integer portion of the quotient of the division between decimals a and b ::Decimal::remainder a b Return the remainder of the division between the two decimals a and b. ::Decimal::abs decimal Return the absolute value of the decimal. ::Decimal::compare a b Compare the two decimals a and b, returning 0 if a == b, 1 if a > b, and -1 if a < b. ::Decimal::max a b Compare the two decimals a and b, and return a if a >= b, and b if a < b. ::Decimal::maxmag a b Compare the two decimals a and b while ignoring their signs, and return a if abs(a) >= abs(b), and b if abs(a) < abs(b). ::Decimal::min a b Compare the two decimals a and b, and return a if a <= b, and b if a > b. ::Decimal::minmag a b Compare the two decimals a and b while ignoring their signs, and return a if abs(a) <= abs(b), and b if abs(a) > abs(b). ::Decimal::plus a Return the result from ::Decimal::+ 0 $a. ::Decimal::minus a Return the result from ::Decimal::- 0 $a. ::Decimal::copynegate a Returns a with the sign flipped. ::Decimal::copysign a b Returns a with the sign set to the sign of the b. ::Decimal::is-signed decimal Return the sign of the decimal. The procedure returns 0 if the number is positive, 1 if it's negative. ::Decimal::is-zero decimal Return true if decimal value is zero, otherwise false is returned. ::Decimal::is-NaN decimal Return true if decimal value is NaN (not a number), otherwise false is returned. ::Decimal::is-infinite decimal Return true if decimal value is Infinite, otherwise false is returned. ::Decimal::is-finite decimal Return true if decimal value is finite, otherwise false is returned. ::Decimal::fma a b c Return the result from first multiplying a by b and then adding c. Rescaling only occurs after completion of all operations. In this way the result may vary from that returned by performing the operations individually. ::Decimal::round_half_even decimal digits Rounds decimal to digits number of decimal points with the following rules: Round to the nearest. If equidistant, round so the final digit is even. ::Decimal::round_half_up decimal digits Rounds decimal to digits number of decimal points with the following rules: Round to the nearest. If equidistant, round up. ::Decimal::round_half_down decimal digits Rounds decimal to digits number of decimal points with the following rules: Round to the nearest. If equidistant, round down. ::Decimal::round_down decimal digits Rounds decimal to digits number of decimal points with the following rules: Round toward 0. (Truncate) ::Decimal::round_up decimal digits Rounds decimal to digits number of decimal points with the following rules: Round away from 0 ::Decimal::round_floor decimal digits Rounds decimal to digits number of decimal points with the following rules: Round toward -Infinity. ::Decimal::round_ceiling decimal digits Rounds decimal to digits number of decimal points with the following rules: Round toward Infinity ::Decimal::round_05up decimal digits Rounds decimal to digits number of decimal points with the following rules: Round zero or five away from 0. The same as round-up, except that rounding up only occurs if the digit to be rounded up is 0 or 5, and after overflow the result is the same as for round- down. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category Decimal of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
decimal, math, tcl CATEGORY
Mathematics COPYRIGHT
Copyright (c) 2011 Mark Alston <mark at beernut dot com> math 1.0.2 Decimal(3tcl)
All times are GMT -4. The time now is 03:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy