Sponsored Content
Full Discussion: Integer/Float Script Problem
Top Forums UNIX for Dummies Questions & Answers Integer/Float Script Problem Post 35458 by danhodges99 on Monday 14th of April 2003 05:34:39 AM
Old 04-14-2003
Integer/Float Script Problem

Hi,

I have a script which takes a value from a file and performs calculations on it. Trouble is that this value is a float not an integer and it errors at the decimal point!
eg. 94.62
I would like to be able to detect the length of the float (in this above case, 5 characters), and simply do a cut -c on the first x characters depending on it's length. Anyone know how to detect the length of this input?

Cheers.Smilie
danhodges99
 

10 More Discussions You Might Find Interesting

1. Programming

math.h: float ceilf(float x)

Good morning, I'm testing the use of ceilf: /*Filename: str.c*/ #include <stdio.h> #include <math.h> int main (void) { float ceilf(float x); int dev=3, result=0; float tmp = 3.444f; printf("Result: %f\n",ceilf(tmp)); return 0; } (1 Reply)
Discussion started by: jonas.gabriel
1 Replies

2. Shell Programming and Scripting

how do i generate random integer using only shell script

Hi All, I need to generate 4 digit random no using only shell script. Please help in this ASAP. Thanks in advance... Regards, sridhar. (1 Reply)
Discussion started by: sridhusha
1 Replies

3. Shell Programming and Scripting

Problem with float calculation and awk

Hi All, can some body help me to script the below logic. Basically am facing problem with float calculation. Also i need this to be done inside a single awk. I tried lot of tuning but still nothing is getting displayed, nor any errors param=50 value=19.23 for(i=0;i<4;i++) {... (2 Replies)
Discussion started by: jisha
2 Replies

4. Shell Programming and Scripting

if clause problem ..err is : integer expression expected

Hi pls help me with this if clause , which is marked in red . It gives me an error saying :- : integer expression expected and it goes to the else part and writes output the WARNING STATEMENTS .. the values of if ; then rcInPAudit and rcInP match each other exactly ..but it does not... (5 Replies)
Discussion started by: rxg
5 Replies

5. Shell Programming and Scripting

Float number format problem -Awk

Here is the script I'm using awk '{print $1,"\t",(($2+$3)/2)-x,"\t",(($2+$3)/2)+x,"\t",$4,"\t",$5}' x=500 $1 I just want to make float numbers (red) like normal numbers (green) output cX 1.65107e+08 1.65108e+08 13 64.2 cX 165112764 165113764 27 ... (7 Replies)
Discussion started by: ruby_sgp
7 Replies

6. Shell Programming and Scripting

if script error: integer expression expected

Hi, i am making a simple program with a optional -t as the 3rd parameter. Submit course assignment -t dir In the script, i wrote: #!/bin/bash echo "this is course: ${1}" echo "this is assignment #: ${2}" echo "late? : ${3}" if then echo "this is late" fi but this gives me a :... (3 Replies)
Discussion started by: leonmerc
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

Converting String To Integer/Float (weird case)

Hi guys, I'm new here. I have a problem at work. One of our scripts was eventually having a bug and only detected recently. Here's the issue and background: Bash Script which calls AWK script Awk script returns a string as per below (example):var1='00000-123'So, when we convert it, the... (18 Replies)
Discussion started by: sekfarok
18 Replies

9. Shell Programming and Scripting

Perl Script Integer Test

Working out a small problem, I have a need of a Perl snippet which might look something like this: use integer; ... if ($changingNumber / 2) { do something; } else { do something else; } ... What I want to happen is for "if" to resolve as "true" every time a whole... (3 Replies)
Discussion started by: LinQ
3 Replies

10. Programming

Python : Problem with " TypeError: float() argument must be a string or a number "

Hello ! I'm creating a CGI which allow to display graph from some data. The datas looks like : 2020-01-13-00-00,384.00,350.00 2020-01-13-06-00,384.00,350.00 2020-01-13-12-00,384.00,350.00 2020-01-13-18-00,384.00,350.00 2020-01-14-00-00,384.00,350.00... (1 Reply)
Discussion started by: Tim2424
1 Replies
hypot(3M)						  Mathematical Library Functions						 hypot(3M)

NAME
hypot, hypotf, hypotl - Euclidean distance function SYNOPSIS
cc [ flag... ] file... -lm [ library... ] #include <math.h> double hypot(double x, double y); float hypotf(float x, float y); long double hypotl(long double x, long double y); DESCRIPTION
These functions compute the length of the square root of x2+ y2without undue overflow or underflow. RETURN VALUES
Upon successful completion, these functions return the length of the hypotenuse of a right angled triangle with sides of length x2and y2PP If the correct value would cause overflow, a range error occurs and hypot(), hypotf(), and hypotl() return the value of the macro HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively. If x or y is +-Inf, +Inf is returned even if one of x or y is NaN. If x or y is NaN and the other is not +-Inf, a NaN is returned. ERRORS
These functions will fail if: Range Error The result overflows. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, the overflow floating-point exception is raised. USAGE
hypot(x,y), hypot(y,x), and hypot(x, -y) are equivalent. hypot(x, +-0) is equivalent to fabs(x). These functions takes precautions against underflow and overflow during intermediate steps of the computation. An application wanting to check for exceptions should call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an exception has been raised. An application should either examine the return value or check the floating point exception flags to detect exceptions. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
fabs(3M), feclearexcept(3M), fetestexcept(3M), isnan(3M), math.h(3HEAD), sqrt(3M), attributes(5), standards(5) SunOS 5.10 1 Sep 2002 hypot(3M)
All times are GMT -4. The time now is 11:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy