Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Decimal numbers and letters in the same collums: round numbers Post 302988540 by bakunin on Tuesday 27th of December 2016 05:13:59 PM
Old 12-27-2016
Quote:
Originally Posted by RudiC
if the field in question contains ANY non-numeric character, use "%s" else use "%f" with an adaptable width.
Darn, you are right. I hate it when you do that to me. ;-)

The regexp can be repaired perhaps: (var ~ /^-*[0-9.]*[0-9]+$/).

Testing for [[:alpha:]] alone will also not do the trick because of "misformed" numbers like: "123.456.789", which should not be treated as numbers despite passing the [[:digit:]]-test. Thinking about it it is not possible to determine "number or not" based on characters alone:

Code:
-123.456  # is a number
123-456.  # is not


I hope this helps.

bakunin

Last edited by bakunin; 12-27-2016 at 06:19 PM..
 

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
strfmon(3C)															       strfmon(3C)

NAME
strfmon - convert monetary value to string SYNOPSIS
Remarks The ANSI C "" construct denotes a variable length argument list whose optional [or required] members are given in the associated comment DESCRIPTION
The function places characters into the array pointed to by s as controlled by the string pointed to by format. No more than maxsize bytes are placed into the array. The format is a character string that contains two types of objects: plain characters, which are simply copied to the output, and conver- sion specifications, each of which results in the fetching of zero or more arguments that are converted and formatted. The arguments are of type see the section for details. The results are undefined if there are insufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments are ignored. A conversion specification is the string flag]...[field_width][right_precision] conversion_character Each element of the sequence is specified as follows: Flags One or more of the following optional flags can be specified to control the conversion: An (equal sign) followed by a single character f which is used as the numeric fill character. The fill character must be repre- sentable in a single byte in order to work with precision and width counts. The default numeric fill character is the space character. This flag does not affect field width filling which always uses the space character. This flag is ignored unless a left precision (see below) is specified. Do not format the currency amount with grouping characters. The default is to insert the grouping characters if defined for the current locale. Specify the style for representing positive and negative currency amounts. Only one of or (plus sign or left parenthesis) may be specified. If is specified, the locale's equivalent of + and - are used (for example, in the locale: an empty string if positive and - if negative). If is specified, negative amounts are enclosed within parentheses. If neither flag is specified, the style is used. Suppress the currency symbol from the output conversion. A minus sign specifying the alignment. If this flag is present all fields are left-justified (padded to the right) rather than right-justified. Field Width w A decimal digit string w specifying a minimum field width in bytes in which the result of the conversion is right-justified (or left-justified if the flag - is specified). The default is zero. Left Precision A followed by a decimal digit string n specifying a maximum number of digits expected to be formatted to the left of the radix character. This option can be used to keep the formatted output from multiple calls to the aligned in the same columns. It can also be used to fill unused positions with a special character as in $***123.45. This option causes an amount to be formatted as if it has the number of digits specified by n. If more than n digit positions are required, this conversion specification is ignored. Digit positions in excess of those actually required are filled with numeric fill character (see the flag above). If grouping has not been suppressed with the flag, and it is defined for the current locale, grouping separators are inserted before the fill characters (if any) are added. Grouping separators are not applied to fill characters even if the fill character is a digit. To ensure alignment, any characters appearing before or after the number in the formatted output such as currency or sign symbols are padded as necessary with space characters to make their positive and negative formats an equal length. Right Precision A period followed by a decimal digit string p specifying the number of digits after the radix character If the value of the right precision p is zero, no radix character appears If a right precision is not included, a default specified by the current locale is used The amount being formatted is rounded to the specified number of digits prior to formatting. Conversion Characters The conversion characters and their meanings are: The argument is formatted according to the locale's international currency format (for example, in the locale: The argument is formatted according to the locale's national currency format (for example, in the locale: Convert to a no argument is converted. The entire conversion specification must be %%. Notes The behavior of the function in a UNIX 2003 conforming application differs from its behavior in a non-conforming application. With the conversion character the function uses the fourth character of the string defined in of the current locale instead of a space as a separa- tor for separating different items in a monetary quantity as dictated by the values of and Only the first three characters will be taken as the currency symbol. As a result, the formatting of internationally formatted monetary quantities may change. EXTERNAL INFLUENCES
Locale The category of the program's locale affects the behavior of this function including the monetary radix character (which may be different from the numeric radix character affected by the category), the grouping separator, the currency symbols and formats. RETURN VALUE
If the total number of resulting bytes including the terminating null byte is not more than maxsize, the function returns the number of bytes placed into the array pointed to by s, not including the terminating null byte Otherwise, -1 is returned, the contents of the array are indeterminate, and errno is set to indicate the error. ERRORS
The function will fail if: Conversion stopped due to lack of space in the buffer. EXAMPLES
The following program segment formats the monetary value using the locale with a left precision of and as the fill character. char string[31]; double amt = -4321.123; setlocale(LC_MONETARY, "en_US.roman8"); strfmon(string, 31, "The amount is %=*#5n.", amt); The string array will contain: The amount is -$*4,321.12. As an other example, given the locale of and the values and --------------------------------------------------------------------------- Conversion Output Comments Specification --------------------------------------------------------------------------- %n $123.45 default formatting -$123.45 $3,456.78 --------------------------------------------------------------------------- %11n $123.45 right align within an 11 character field -$123.45 $3,456.78 --------------------------------------------------------------------------- %#5n $ 123.45 align columns for values up to 99,999 -$ 123.45 $ 3,456.78 --------------------------------------------------------------------------- %=*#5n $***123.45 specify a fill character -$***123.45 $*3,456.78 --------------------------------------------------------------------------- %=0#5n $000123.45 fill characters do not use grouping -$000123.45 even if the fill character is a digit $03,456.78 --------------------------------------------------------------------------- %^#5n $ 123.45 disable the grouping separator -$ 123.45 $ 3456.78 --------------------------------------------------------------------------- %^#5.0n $ 123 round off to whole units -$ 123 $ 3457 --------------------------------------------------------------------------- %^#5.4n $ 123.4500 increase the precision -$ 123.4500 $ 3456.7810 --------------------------------------------------------------------------- %(#5n $ 123.45 use an alternative positive/negative style ($ 123.45) $ 3,456.78 --------------------------------------------------------------------------- %!(#5n 123.45 disable the currency symbol ( 123.45) 3,456.78 --------------------------------------------------------------------------- AUTHOR
was developed by HP. SEE ALSO
localeconv(3C), thread_safety(5). STANDARDS CONFORMANCE
strfmon(3C)
All times are GMT -4. The time now is 06:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy