Multiplying Floats/Decimals


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiplying Floats/Decimals
# 1  
Old 08-02-2007
Multiplying Floats/Decimals

Is there a way that i can get something like this to work:

Number=`expr 80 \* 10.69`

i.e. To multiply an integer by a decimal or a decimal by a decimal etc...?
thanks
# 2  
Old 08-02-2007
One approch among many...

n=$(echo |awk '{ print 80*10.69}')
# 3  
Old 08-02-2007
Thanks. How could i do something like this:

Number=$(echo | awk '{ print $TEST*10.69}')

where $TEST is some integer?
# 4  
Old 08-02-2007
Multiplying Floats/Decimals

Use "bc" here:

$ Number=`echo 80 \* 10.69 |bc`; echo $Number
855.20
# 5  
Old 08-02-2007
Quote:
Originally Posted by jaduks
Use "bc" here:

$ Number=`echo 80 \* 10.69 |bc`; echo $Number
855.20
This gives me an error:
line 34: bc: command not found
# 6  
Old 08-02-2007
Multiplying Floats/Decimals

Check whether "bc" is there in your machine or not.
It should be here : /usr/bin/bc (check with command: "whereis bc", check your PATH also to execute bc),
Hope this helps :-)
# 7  
Old 08-02-2007
not on my machine Smilie

is there some other way i can do this. i realise that it is really simple so there must be another easy way
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Extracting floats from a string in Python

I have this script which can calculate the total of numbers given in a string total = 0 for c in '0123456789': total += int(c) print total How should I modify this script to find the total of if the numbers given in the string form have decimal places? That is, how do I need to modify... (2 Replies)
Discussion started by: faizlo
2 Replies

2. Programming

Multiplying 2D arrays using fork()

HI, i am trying to multiply 2 2D arrays (a,b) using fork. The answer will be at c. Each child have to calculate 1 row of c. The code is right, as i think of it, with no errors but i dont get the correct c array... I think there is maybe a mistake in i dimension ... Anyway, here is the code: ... (16 Replies)
Discussion started by: giampoul
16 Replies

3. Shell Programming and Scripting

Multiplying array element

I am trying to take all the elements of an array and multiply them by 2, and then copy them to a new array. Here is what I have i=0 for true in DMGLIST do let DMGSIZES2="${DMGSIZES}"*2 let i++ done unset i echo ${DMGSIZES2} It does the calculation correctly for the first element,... (7 Replies)
Discussion started by: nextyoyoma
7 Replies

4. Programming

problem in multiplying arrays

Hi, this is my code.It's simple : there are 2 2D arrays and the multiplied to C. #include<stdio.h> #include<sys/shm.h> #include<sys/stat.h> #include<stdlib.h> main() { int *A; //A int *B; //B int *C; //C int i,j,x,k,d; int id; ... (17 Replies)
Discussion started by: giampoul
17 Replies

5. Shell Programming and Scripting

Calculation with floats

I want to make computations using floats. This cannot be done with csh. ksh seem to have a problem as well. What is good shell for computations without having to resort to bc or awk? How about python? (5 Replies)
Discussion started by: kristinu
5 Replies

6. Shell Programming and Scripting

integers, floats and text

I am using gawk in a dos shell in windows xp and want to read a datafile and reformat it. The datafile consists of columns of integers, floating point numbers and text strings. Each column is a fixed width and each column contains the same data type, eg all integers, all text. I am looking for a... (0 Replies)
Discussion started by: lookingfor help
0 Replies

7. Shell Programming and Scripting

problem with AWK and floats below 0

Hello. I have a problem with AWK and floats below 0 in a script. It may be simplified to this line (please, take into account that my "locale" is Spanish, so the system will read "," as decimal separator): echo -1,25 2,55745 0,33 ,278 | awk '{print $1+1, $2+1, $3+1, $4+1}'... getting: -0,25... (4 Replies)
Discussion started by: JCastro
4 Replies

8. Shell Programming and Scripting

bash: dividing/multiplying variables resulting in decimals

(4 Replies)
Discussion started by: puddy
4 Replies

9. Shell Programming and Scripting

convert Regular decimals to Packed decimals

Hi, I am trying to find if there is a way to convert regular decimal values to Paced decimal values. I tried to find a c program but I could get a Packed converted to regular decimal not the other way round. If not unix please let me know if any other progrimming language I can use to do... (2 Replies)
Discussion started by: mgirinath
2 Replies

10. Shell Programming and Scripting

Error only when multiplying two numbers

Hi $ a=10 ; b=2 $ expr $a + $b 12 $ expr $a - $b 8 $ expr $a / $b 5 $ expr $a * $b expr: syntax error Any idean why I am getting this error only when multiplying two numbers. Whats the exact syntax? Thanks a lot to all in advance CSaha (5 Replies)
Discussion started by: csaha
5 Replies
Login or Register to Ask a Question