Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Decimal numbers and letters in the same collums: round numbers Post 302988537 by RudiC on Tuesday 27th of December 2016 04:02:02 PM
Old 12-27-2016
I'm afraid there's a logic flaw in the format determination in above posts: if the field in question contains ANY non-numeric character, use "%s" else use "%f" with an adaptable width. So, the (var ~ /[[:digit:]]/) doesn't lead nowhere - although it doesn't hurt, either, in above constellations. Had you reversed the sequence of the two tests, the "n3d5" field would have received the wrong format string.
These 2 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Letters, Numbers or Alphanumerical

How do I check if a variable consisted of letters, numbers or both letters and numbers? For example, I have a variable $X and I want to print "1" if it contains only letters, "2" if it contains only numbers and "3" if it contains both (2 Replies)
Discussion started by: sleepster
2 Replies

2. UNIX for Dummies Questions & Answers

Help! scrolling numbers and letters

Hello all I am a unix newbie.... I have a sun netra t1 and it is freaking out I am connected to it through a console port, and it is just spitting out a ton on numbers and letters like below its just keeps going and going. I have tried rebooting it and I cannot get it back to any kind of a... (1 Reply)
Discussion started by: intraining11
1 Replies

3. Shell Programming and Scripting

decimal numbers

Hi friends How can I use "for loop" for decimal numbers? ex: 0.1 < x < 0.6 I used this commands but does'nt work. LIMIT=0.6 for ((x=0.1; x<=LIMIT; x++)) do - - - done Many thanks (1 Reply)
Discussion started by: snow
1 Replies

4. Shell Programming and Scripting

Regarding decimal numbers

Hello... I am new to unix and I am wondering if in a C-shell script , Are we supposed to use only whole numbers........ for example..if a program needs to calculate the average of some numbers........ @ avg = (($1 +$2 + $3)/3)) is returning a whole number.........How can a decimal be... (7 Replies)
Discussion started by: ravindra22
7 Replies

5. Shell Programming and Scripting

sed command, look for numbers following letters

If I have a set of strings, C21 F231 H42 1C10 1F113 and I want to isolate the ints following the char, what would the sed string be to find numbers after letters? If I do, *, I will get numbers after letters, but I am looking to do something like, sed 's/*/\t*/g' this will give me... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

6. Shell Programming and Scripting

reducing values in columns with both numbers and letters

Hi, I columns with both number and letters however i need the number 4 trimmed off the lines that have 3 numbers in them so it just because the 2 preceding numbers only For example V25QG2-K18QG-V25CG2 L26HG-L17HA-L26CG I434QD1-L19HB2-I434CD1 I434QD1-A31QB-I434CD1 ... (7 Replies)
Discussion started by: olifu02
7 Replies

7. Shell Programming and Scripting

awk : match only the pattern string , not letters or numbers after that.

Hi Experts, I am finding difficulty to get exact match: file OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE="" DHCP_ENABLE=0 INTERFACE_NAME="lan3:1"... (6 Replies)
Discussion started by: rveri
6 Replies

8. Shell Programming and Scripting

Sorting mixed numbers and letters

Hello, I have a file such as this: chr1 chr2 chr1 chr2 chr3 chr10 chr4 chr5 chrz chr1AI want to sort it, I use this command: sort -k1 -th -n testfilebut I get this output, how can I fix this? chr1 chr1 chr10 chr1A chr2 chr2 (3 Replies)
Discussion started by: Homa
3 Replies

9. UNIX for Dummies Questions & Answers

sed - extract a group of Letters/numbers

I have a file with hundreds of lines in it. I wanted to extract anything that matches the following: KR followed by 4 digits: example KR1201 cat list | sed "s///g" Is the closest I've come, and obviously it is not what I want. This would remove all of the items that I want and leave me... (2 Replies)
Discussion started by: newbie2010
2 Replies

10. Shell Programming and Scripting

[FUN] Numbers to Roman letters/num

Heyas Just a little fun script (code block) i'd like to share for fun. #/bin/bash # roman.sh # # Function # num2roman() { # NUM # Returns NUM in roman letters # input=$1 # input num output="" # Clear output string len=${#input} # Initial length to count down ... (9 Replies)
Discussion started by: sea
9 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 05:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy