Sponsored Content
Top Forums Shell Programming and Scripting truncate string to integer or decimal Post 302562120 by jayan_jay on Thursday 6th of October 2011 04:23:02 AM
Old 10-06-2011
Code:
$ echo $str | sed 's,[aA-zZ],,g' | cut -d'.' -f1

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help: How do I ADD non-integer (decimal) values?

I am trying to create a script that will read from a file two non-integer values (decimals) and add those values together. For example, I want to add 1.51 and -2.37 together and get the sum. Any ideas? Thanks! (2 Replies)
Discussion started by: limshady411
2 Replies

2. Shell Programming and Scripting

Compare integer value with decimal

Hi all, I have a issue... Is it possible to compare integer value with decimal value. If it is not possible,then how can i compare 2 decimal values in born shell.thanks! (3 Replies)
Discussion started by: MARY76
3 Replies

3. Shell Programming and Scripting

Converting a decimal into integer

Hi all, I'm trying to convert a decimal number into an integer number; I'm doing this: n=`echo |awk '{ print "'"$mem"'"*10}'` where the variable mem is equal to 3.7 I'd like to obtain 37, but the expression above gives me 30. Help please!!!! thx a lot (4 Replies)
Discussion started by: idro
4 Replies

4. Shell Programming and Scripting

Converting decimal to integer

The shell mentioned below will show a warning if the page takes more than 6 seconds to load. The problem is that myduration variable is not an integer. How do I convert it to integer? myduration=$(curl http://192.168.50.1/mantisbt/view.php?id=1 -w %{time_total}) > /dev/null ; ] && echo... (3 Replies)
Discussion started by: shantanuo
3 Replies

5. Shell Programming and Scripting

Truncate string variable

Hi, I want to truncate a string variable, returned in the script. In perl I used the below and it worked. BRNo=BR12345 $BR = substr($BRNo, 2, 7) How can I do it in sh. Thanks ! (8 Replies)
Discussion started by: script2010
8 Replies

6. UNIX for Dummies Questions & Answers

compare decimal and integer values in if in bash shell

i need to do camparisions like the below. For the case when first=10 and second=9.9 the scripts displays process failed. I need to be able to convert the values to integer before doing the comparision. Like 9.9 should be rounded over to 10 before doing comparision. Please advice how can... (3 Replies)
Discussion started by: nehagupta
3 Replies

7. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

8. Shell Programming and Scripting

[Solved] need to convert decimal to integer

Using below command awk 'NR==FNR{A=$1;next} {sum+=($2*A)}END{OFMT="%20f";print int(sum)}' Market.txt Product.txt answer:351770174.00000 how to convert this to 351770174. when i try with below command i am getting different result. awk 'NR==FNR{A=$1;next}... (3 Replies)
Discussion started by: katakamvivek
3 Replies

9. Shell Programming and Scripting

Column value can be Two integer post decimal or blank

Hi Experts, Need your advice. I have a csv file in which column value can contain two integer post decimal(like 1.00, 13.00,12.15, 2.43) or blank. Tried the below code but not working. awk -F "|" '{ if ($39 !~ /^+\.{2}$ || $39 != "") {print "165: Quantity decimal values are not correct... (2 Replies)
Discussion started by: as7951
2 Replies

10. 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
Tcl_GetInt(3)						      Tcl Library Procedures						     Tcl_GetInt(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_GetInt, Tcl_GetDouble, Tcl_GetBoolean - convert from string to integer, double, or boolean SYNOPSIS
#include <tcl.h> int Tcl_GetInt(interp, src, intPtr) int Tcl_GetDouble(interp, src, doublePtr) int Tcl_GetBoolean(interp, src, boolPtr) ARGUMENTS
Tcl_Interp *interp (in) Interpreter to use for error reporting. const char *src (in) Textual value to be converted. int *intPtr (out) Points to place to store integer value converted from src. double *doublePtr (out) Points to place to store double-precision floating-point value converted from src. int *boolPtr (out) Points to place to store boolean value (0 or 1) converted from src. _________________________________________________________________ DESCRIPTION
These procedures convert from strings to integers or double-precision floating-point values or booleans (represented as 0- or 1-valued integers). Each of the procedures takes a src argument, converts it to an internal form of a particular type, and stores the converted value at the location indicated by the procedure's third argument. If all goes well, each of the procedures returns TCL_OK. If src does not have the proper syntax for the desired type then TCL_ERROR is returned, an error message is left in the interpreter's result, and noth- ing is stored at *intPtr or *doublePtr or *boolPtr. Tcl_GetInt expects src to consist of a collection of integer digits, optionally signed and optionally preceded by white space. If the first two characters of src after the optional white space and sign are "0x" then src is expected to be in hexadecimal form; otherwise, if the first such character is "0" then src is expected to be in octal form; otherwise, src is expected to be in decimal form. Tcl_GetDouble expects src to consist of a floating-point number, which is: white space; a sign; a sequence of digits; a decimal point; a sequence of digits; the letter "e"; a signed decimal exponent; and more white space. Any of the fields may be omitted, except that the digits either before or after the decimal point must be present and if the "e" is present then it must be followed by the exponent number. Tcl_GetBoolean expects src to specify a boolean value. If src is any of 0, false, no, or off, then Tcl_GetBoolean stores a zero value at *boolPtr. If src is any of 1, true, yes, or on, then 1 is stored at *boolPtr. Any of these values may be abbreviated, and upper-case spellings are also acceptable. KEYWORDS
boolean, conversion, double, floating-point, integer Tcl Tcl_GetInt(3)
All times are GMT -4. The time now is 04:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy