[Solved] need to convert decimal to integer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] need to convert decimal to integer
# 1  
Old 09-28-2012
[Solved] need to convert decimal to integer

Using below command
Code:
awk 'NR==FNR{A[NR]=$1;next}
{sum+=($2*A[FNR])}END{OFMT="%20f";print int(sum)}' Market.txt Product.txt

answer:
Code:
351770174.00000

how to convert this to 351770174.

when i try with below command i am getting different result.
Code:
awk 'NR==FNR{A[NR]=$1;next}
{sum+=($2*A[FNR])}END{OFMT="%20d";print sum}' Market.txt Product.txt

answer:
Code:
1040187392.

Please tell me how to concert decimal to integer.

Last edited by Franklin52; 09-28-2012 at 10:33 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 09-28-2012
have u tried...

Code:
 
awk 'NR==FNR{A[NR]=$1;next}
{sum+=($2*A[FNR])}END{OFMT="%20.0f";print int(sum)}' Market.txt Product.txt

# 3  
Old 09-28-2012
ya i tried..
i a getting different answer as 1040187392

---------- Post updated at 09:01 AM ---------- Previous update was at 08:56 AM ----------

its working thanks...
# 4  
Old 09-28-2012
Code:
END {printf "%20d\n", sum}

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Programming

Urgent help needed.. C++ program to convert decimal to hexa decimal

Hi , seq can be 0...128 int windex = seq / 8; int bindex = seq % 8; unsigned char bitvalue = '\x01' << (7-bindex) ; bpv.bitmapvalue = bitvalue; This is the part of a program to convert decimal to bitmap value of hexadecimal. I want this to change to convert only to... (1 Reply)
Discussion started by: greenworld123
1 Replies

4. UNIX for Dummies Questions & Answers

Convert hexa decimal to decimal

Hi, I want to convert two hexadecimal numbers to decimal using unix command line. 1cce446295197a9d6352f9f223a9b698 fc8f99ac06e88c4faf669cf366f60d I tried using `echo "ibase=16; $no |bc` printf '%x\n' "1cce446295197a9d6352f9f223a9b698" but it doesn't work for such big number it... (4 Replies)
Discussion started by: sudhakar T
4 Replies

5. Shell Programming and Scripting

truncate string to integer or decimal

From strings stored in variables, I need to isolate and use the first numerical value contained within them. I will need to know how to produce an integer as well as a floating point decimal. It needs to work on any string regardless of what types of characters (if any) are preceding or following... (3 Replies)
Discussion started by: bradlecat
3 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

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

8. 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

9. 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

10. 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
Login or Register to Ask a Question