Sponsored Content
Homework and Emergencies Homework & Coursework Questions Unix/Linux Math Decimal to Whole Number Format? Post 302549725 by Iceman69 on Tuesday 23rd of August 2011 10:18:14 PM
Old 08-23-2011
Unix/Linux Math Decimal to Whole Number Format?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
The problem? I hope I fill this out correctly. I have a program that runs like a cash register. It works and functions correctly. The question is how can I make it "Not" use decimal's and use whole numbers?


2. Relevant commands, code, scripts, algorithms:
The code:

12 clear
13 total=0
14 grandtotal=0
15 taxtotal=0
16 most=0
17 least=0
18 counter=0
19 echo "Enter a price:"
echo "Press Enter twice when you are done to see the total."

20 echo
21 echo -n "Price: $" ; read a
22 echo
23 most=$a
24 least=$a
25 total=$a
26 while test $a
27 do
28 echo -n "Please enter another price: $"
29 read a

30 echo
31 let counter=$counter+1
32 if [[ $a = "" ]]
33 then break
34 else
35 (( total += a))
36 if [[ $a -lt $least ]]
37 then least=$a
38 fi
39 if [[ $a -gt $most ]]

40 then most=$a
41 fi
42 fi
43 done
44 clear
45 echo -n "The total is: $"
46 echo $total
47 echo
48 if [ $total -gt 1000 ]
49 then tax=.03

50 else
51 tax=.06
52 fi
53 taxtotal="$tax*$total"
54 echo -n "The Tax is: $"
55 echo $taxtotal | bc
56 echo
57 echo -n "The Grand Total is: $"
58 grandtotal=$total+$taxtotal
59 echo $grandtotal | bc

50 echo
51 echo -n "The total number of items is: "
52 echo $counter
53 echo
54 echo -n "The most expensive item was: $"
55 echo $most
56 echo
57 echo -n "The lowest item was: $"
58 echo $least
59 echo


3. The attempts at a solution (include all code and scripts):

I have tried changing lines 49 and 51 to
49 then tax=$total=3*100
49 then tax="$total=3*100"
49 then tax="$total/3*100"

51 tax=$total=6*100
51 tax="$total=6*100"
51 tax="$total/6*100"

This has been a self taught class for the most part, the stuff we are asked to do is way beyond what INTRO is suppose to be about in a 9 week class.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Baker College, Allen Park, Michigan, United States, Mahmoud Zali, Intro to Linux/Unix LUX205 (no link on campus)

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Number format conversion in UNIX

Hi All, I want to convert Scientific number format into normal number format using unix script or using any command of unix. e.g 1.55397e+09 into 1553970000 Thanks in advance Kamal (1 Reply)
Discussion started by: kamal_418
1 Replies

2. Shell Programming and Scripting

format decimal in ksh

hi all, in ksh, how do i format a decimal number (e.g 3381.19) to integer (e.g 3381). This number is average time response for server in millisec and i wanted to display it in a more readable format i.e in seconds without any decimals. thanks in advance. (2 Replies)
Discussion started by: cesarNZ
2 Replies

3. Shell Programming and Scripting

Decimal format

Hello Friends, I have a file with below format... 1234,Hary,102.55 4567,Maria,250.40 78942,suzan,261.60 48965,Harun,179.32 And I want to check the last column. If the decimal value of the last column is below 50, I need that column else ignore that column. Can anyone help me out? (3 Replies)
Discussion started by: mziaullah
3 Replies

4. Shell Programming and Scripting

IP address to decimal format conversion

I have a file which consist of some class 4 IP address as 172.16.112.50 172.16.112.50 172.16.112.50 172.16.112.100 192.168.1.30 172.16.112.100 172.16.112.50 172.16.112.50 172.16.112.50 i want to store them in pure decimal notations instead of the given dotted decimal formats e.g.... (2 Replies)
Discussion started by: vaibhavkorde
2 Replies

5. Shell Programming and Scripting

number of digits after decimal

Hi All, I have a file of decimal numbers, cat file1.txt 1.1382666907 1.2603107334 1.6118799297 24.4995857056 494.7632588468 560.7633734425 ..... I want to see the output as only 7 digits after decimal (5 Replies)
Discussion started by: senayasma
5 Replies

6. Shell Programming and Scripting

Awk - Summation in Proper decimal Format

Hi I am executing below command to do summation on 46th coloumn. cat File1| awk -F"|" '{p += $46} END { printf"Column Name | SUM | " p}' I am getting output as Column Name | SUM | 1.01139e+10 Here I want output in Proper decimal format. Can someone tell me what change is required for same? (1 Reply)
Discussion started by: sanranad
1 Replies

7. Shell Programming and Scripting

Sort Decimal number in UNIX

Hello Everyone, In one of my script, I would like to sort the decimal numbers. For e.g. If I have numbers like 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.10 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 I would like to sort them 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.2 7.3 7.4... (3 Replies)
Discussion started by: sachinrastogi
3 Replies

8. UNIX for Dummies Questions & Answers

Linux Math Help

I am struggling with scripting this challenge a friend and I have. You have file1 and its contents is a single number you have file 2 and its contents are a different number you want to add file1 to file2 and have the output be put into file3 (3 Replies)
Discussion started by: minkyboodle
3 Replies

9. UNIX for Dummies Questions & Answers

How to control the decimal points for p-values in scientific format?

Dear all, I have a txt file with only one column which contains p values. My data looks like this: 5.04726976606584e-190 2.94065711152402e-189 2.94065711152402e-189 9.19932135717279e-176 1.09472516659859e-170 1.24974648916809e-170 0.1223974648916 0.9874974648916 ... what I want... (2 Replies)
Discussion started by: forevertl
2 Replies
SSH2_METHODS_NEGOTIATED(3)						 1						SSH2_METHODS_NEGOTIATED(3)

ssh2_methods_negotiated - Return list of negotiated methods

SYNOPSIS
array ssh2_methods_negotiated (resource $session) DESCRIPTION
Returns list of negotiated methods. PARAMETERS
o $session - An SSH connection link identifier, obtained from a call to ssh2_connect(3). RETURN VALUES
EXAMPLES
Example #1 Determining what methods were negotiated <?php $connection = ssh2_connect('shell.example.com', 22); $methods = ssh2_methods_negotiated($connection); echo "Encryption keys were negotiated using: {$methods['kex']} "; echo "Server identified using an {$methods['hostkey']} with "; echo "fingerprint: " . ssh2_fingerprint($connection) . " "; echo "Client to Server packets will use methods: "; echo " Crypt: {$methods['client_to_server']['crypt']} "; echo " Comp: {$methods['client_to_server']['comp']} "; echo " MAC: {$methods['client_to_server']['mac']} "; echo "Server to Client packets will use methods: "; echo " Crypt: {$methods['server_to_client']['crypt']} "; echo " Comp: {$methods['server_to_client']['comp']} "; echo " MAC: {$methods['server_to_client']['mac']} "; ?> SEE ALSO
ssh2_connect(3). PHP Documentation Group SSH2_METHODS_NEGOTIATED(3)
All times are GMT -4. The time now is 03:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy