Help with decimal points


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with decimal points
# 1  
Old 07-31-2014
Help with decimal points

Hi All,

I would like to set decimal point to 16 in the following bash script but it has syntax error at }:

Code:
awk '{printf"%.16e", (a<500,a++,$1/(a*1.1212121212121229e-02))}' input.dat >output.dat

How may I set it in the correct way please? Thank you very much!

Last edited by sxiong; 07-31-2014 at 01:11 PM.. Reason: Add CODE tags.
# 2  
Old 07-31-2014
I'm pretty sure your construct (a<500,a++,$1/(a*1.1212121212121229e-02)) is not understood by awk. What be your intention?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-31-2014
Please explain in English what this awk script is supposed to do. I can make a few wild guesses, but none of them make any sense to me.

Then note that awk uses double precision floating point arithmetic (which gives you about 15-17 significant digits on individual values). Rounding errors may significantly reduce the precision of your results depending on the ranges of values being multiplied and divided.

What does the data in input.dat look like?
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 07-31-2014
Thanks for your kind replies. I want to divide the data in my input.dat by a times a constant as a goes from 1 to 499. I used
Code:
awk '{print (a<500,a++,$1/(a*1.121212121212121229e-02))}' input.dat >output.dat

and got the desired values with 6 digits although the code is far from perfect. Here is part of the input:
Code:
1.0805574801665273e+01
1.0631847858835727e+01
1.0461243720756954e+01
1.0293701484862595e+01
1.0129161486782039e+01

and output:
Code:
1 0 963.74
1 1 474.123
1 2 311.01
1 3 229.522
1 4 180.682

So I'd like to find a way to set the decimal point of output data to 16. Would you please shed light on the problem? Thanks a lot!

Last edited by sxiong; 07-31-2014 at 01:55 PM..
# 5  
Old 07-31-2014
Print two integers and one floating point?
Code:
awk '{printf "%d %d %.16f\n",(a<500),a++,$1/(a*1.121212121212121229e-02)}' input.dat

You get exponential notation if you change f to e.
This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 07-31-2014
That is exactly what I want. Thank you very much! I forgot I have three columns in the output... Thanks again!
# 7  
Old 07-31-2014
Please use code tags as required by forum rules!

How about
Code:
awk '{print a<500,a++,$1/(a*1.121212121212121229e-02)}'  OFMT="%.16g" file
1 0 963.7404552836596
1 1 474.1229450561879
1 2 311.0099484549365
1 3 229.5217222976119
1 4 180.6823400344904

This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Grep commands for numbers w/decimal points

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: Is there a grep commands for numbers w/decimal points Display lines for students with GPA above 3.69 but less... (3 Replies)
Discussion started by: jetoutant
3 Replies

2. Shell Programming and Scripting

Using awk to place decimal points at proper position

Hi, I have one input file which is delimited by pipe. I want to put decimal points in this input file at particular position in particular column and also get the negative sign (if any) at start of that column. $ cat Input_file.txt 11|10102693|1|20151202|10263204|20151127|N|0001... (7 Replies)
Discussion started by: Prathmesh
7 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

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

5. Shell Programming and Scripting

Shell arithmetic : operations on decimal points

i am having a varialbe a , which is input to my file i want to multiply this input with value .43, and assign it to variable b. i tried it as below: #!/bin/sh a=$1 b=`expr $1\*0.43` echo b=$b error : expr: non-integer argument Please tell me , how to do this. Thanks (10 Replies)
Discussion started by: rishifrnds
10 Replies

6. Shell Programming and Scripting

Reducing the decimal points of numbers (3d coordinates) in a file; how to input data to e.g. Python

I have a file full of coordinates of the form: 37.68899917602539 58.07500076293945 57.79100036621094 The numbers don't always have the same number of decimal points. I need to reduce the decimal points of all the numbers (there are 128 rows of 3 numbers) to 2. I have tried to do this... (2 Replies)
Discussion started by: crunchgargoyle
2 Replies

7. Shell Programming and Scripting

How to sort when there is variable length decimal points.?

Hi Experts, Quick quesion: I want to sort this in the file , but not working, when using # sort file name 305.932 456.470 456.469 456.468 456.467 172.089 456.467 456.466 456.465 111.573 111.578 111.572 111.572 87.175 87.174 75.898 (4 Replies)
Discussion started by: rveri
4 Replies

8. UNIX for Dummies Questions & Answers

accuracy of output - decimal points

Is there a way when using awk to specify the number of decimal points needed for the output? (2 Replies)
Discussion started by: cosmologist
2 Replies

9. Shell Programming and Scripting

how to get rid of all chars after the last decimal points

Hi All, Here is my original string: 192.168.2.1.8088. The target string I want: 192.168.2.1, how can I use awk or sed or other command to get rid of .8088 in the string? Thanks, Ray (9 Replies)
Discussion started by: rluo
9 Replies

10. UNIX and Linux Applications

Gnuplot question: how to plot 3D points as colored points in map view?

I have a simple gnuplot question. I have a set of points (list of x,y,z values; irregularly spaced, i.e. no grid) that I want to plot. I want the plot to look like this: - points in map view (no 3D view) - color of each point should depend on its z-value. - I want to define my own color scale -... (0 Replies)
Discussion started by: karman
0 Replies
Login or Register to Ask a Question