Questions tagged [floating-point]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
72 views

POSIX floating comparison

working with a legacy system, here I'm connecting with sqlplus to store the returned value in a variable and its worked fine with me but the problem with compearing with floating values a numeric/...
1
vote
2answers
185 views

How many decimal places could awk's rand() give you?

How many decimal places will rand() give? I assume rand() value can't be any completely arbitrary number from 0 up to excluding 1 and that it's limited to a certain amount of decimal places or ...
4
votes
1answer
761 views

How to drop decimal place on numbers in a JSON array?

What shell command in a bash script could be issued to efficiently strip all the decimal places from the numbers in a JSON file such as this: [ { "IMSKU": "1000001", ...
0
votes
1answer
220 views

Blender fails to launch - Floating Point Exception (Core Dumped)

I am new to Linux so excuse my noob. I haven't been able to find an answer for this anywhere nor have I even found anyone with a similar problem and no one on discord has an answer either.. I am ...
0
votes
3answers
32 views

Discard integer and keep floating point

I'm trying to remove an integer from a decimal value that I currently have. current syntax: h=$(echo "scale=2; (($e/$g/$g))" | bc) echo $h The following is used to convert seconds to minutes ...
1
vote
0answers
26 views

Gnuplot Precission

Does anyone know whether there is a way to run gnuplot with quadruple arithmetic precision? E.g. When you want to plot a line and you want to subtract a value like "2....
29
votes
2answers
2k views

Which is the current decimal separator?

Say I have a POSIX shell script that needs to run on different systems/environments that I do not control, and needs to remove the decimal separator from a string that is emitted by a program that ...
5
votes
1answer
1k views

seq decimal separator

Using a seq command with floating point numbers, my output comes with commas instead of dots as decimal separators, despite using dots in the input: seq 0.1 0.3 1.3 0,1 0,4 0,7 1,0 1,3 I assumed ...
0
votes
0answers
125 views

Restricting the awk output of df sum to 2 decimal points [duplicate]

I have a script to calculate the cumulative capacity in all the servers. for i in `cat servers` do ssh user@$i "df -t xfs --total | grep total"; done > capout.txt awk -vDT="Capacity" ' {...
1
vote
4answers
2k views

Floating point numbers in bash [duplicate]

Let's say I have a variable and I want to print 5 significant digits after I multiplied it by 1000. zsh can do it: zsh$ x=2.8026407e+00 zsh$ printf "%.5g\n" "$(( 1000*${x} ))" zsh> 2802.6 Can ...
2
votes
1answer
90 views

Understanding the od utility output in regards to floats 'od -t f'

I am making my own od utility based on the Single UNIX Specification and I am confused on how the representation of floats is handled e.g. od -t f. I have a perfectly functioning utility otherwise ...
1
vote
1answer
4k views

How to change regional settings in Linux, including decimal point

I was on Linux Mint, now I'm trying Ubuntu 18 main distro. At top of Gnome day of week/time is displayed. That's where I started, wanting to change it to English having set regional to Russian via GUI,...
1
vote
3answers
2k views

Rounding off to nearest number

I have a file with data like this vserver-1 vserver-1_root 0.95 0.0019043 0.948047 vserver-1 home 10.00 8.25 1.75 vserver-1 usr 95 45.65 39.35 vserver-1 file0 100 89.15 10.85 Desired formatted ...
2
votes
1answer
710 views

Why is LDBL_MAX 1.18973E+4932 and how is this possible?

If I write a C program to say the value of LDBL_MAX the largest value for a long double, #include <float.h> #include <stdio.h> int main(void) { const long double max = LDBL_MAX; ...
3
votes
2answers
519 views

Why does $((0.1)) expand to 0.10000000000000001 in zsh?

In zsh: $ echo $((0.1)) 0.10000000000000001 While in other shells with floating point arithmetic expansion: $ ksh93 -c 'echo $((0.1))' 0.1 $ yash -c 'echo $((0.1))' 0.1 Or awk: $ awk 'BEGIN{print ...
0
votes
1answer
271 views

Setting Input field to 2 decimal points (Price)

I am currently trying to input prices into a .txt file. So i want it when the user input:1.1 Instead of 1.1, I want it to become 1.10 instead. As it would look better for the table I am trying to ...
8
votes
2answers
8k views

Can bash do floating-point arithmetic without using an external command? [duplicate]

I have read that bash can do integer arithmetic without using an external command, for example: echo "$((3 * (2 + 1)))" Can bash also do floating-point arithmetic without using an external command?
0
votes
3answers
504 views

Only allow floating points regex

How can I check if a specific string is a floating points? This are possible floating points: 12.245 +.0009 3.11e33 43.1E11 2e-14 This is what I tried: grep "^[+\-\.0-9]" grep "^[+-]*[0-9]" grep "^...
1
vote
1answer
585 views

Checking that a decimal number is in a range in bc

I've written this if, that is obviously not working, and I still can't manage to get over it: #LASTEFFECTIVEHASH if (( $(echo "$LASTEFFECTIVEHASHMINVAL < $LASTEFFECTIVEHASH < $...
3
votes
3answers
2k views

How to compare two float values in ksh?

To compare float values below command is working fine in bash, But not working in ksh on AIX. if (( $(bc <<< " 5.3 >= 5.3") ));then echo "hi";else echo "bye";fi`, I had tried in so many ...
1
vote
3answers
403 views

Adding zero in front of small decimal places [duplicate]

so when I'm coding Im trying to have the output print out 0.12 instead of .12. Here is my code below echo -n "What is the total cost? "; read cents cost=$(echo "scale =2;$cost_in_cents/100" | bc); ...
2
votes
1answer
378 views

Decimal to Hexadecimal conversion working in Linux but not in Unix

I want to convert a decimal number to hexadecimal number. I used the command : printf '%X\n' 053698180 This command is working perfectly fine on Linux server. But throwing the below error when ...
1
vote
4answers
4k views

Regular expression to match floating point numbers in shell script

I'm using a regular expression to match floating point numbers: for f in $float_numbers ; do if [ $f =~ "[0-9]*\.?[0-9]*" ] ; then echo "****f is $f ****" fi done where $...
2
votes
2answers
3k views

Convert exponential notation to decimal number in awk

I have space-separated file. This file contains text as well as numbers in exponential format. I want to convert exponential numbers to actual decimal values. Can someone suggest how I can achieve ...
5
votes
1answer
764 views

Bash shell decimal test [duplicate]

My shell is bash and I have three variables x=5; y=7; z=7.5 I am trying to use the below statement to test the equality of variables $y and $z as shown below Command: test $z -eq $y; echo $? But, it ...
0
votes
1answer
962 views

Unix command to return maximum float value out of two after subtraction

This is similar to question about getting the minimum/maximum of two numbers, but I'm interested to do the same with float numbers. So basically I'm trying to use shell arithmetic expansion using the ...
0
votes
1answer
359 views

Is clock_getres the proper function for obtaining the resolution for Ubuntu 16.04 clock_gettime()?

Is clock_getres the proper function for obtaining the resolution for Ubuntu 16.04 clock_gettime()? If it is , how do I use the result to do this calculation? 64 bit integer has 15 base 10 digits of ...
0
votes
2answers
480 views

Convert bash loop index to floating-point

I need to use the index i in a loop such as for i in {0..10..5} in a floating-point calculation. What is the simplest way to convert i to floating-point? Variations on i=$(bc -l <<< "scale=7;...
1
vote
1answer
2k views

Wrong output in comparing floats

I'm trying to compare two floats in bash and something is going wrong. Here is the code sample based on solution here num1=0.502E-01 num2=0.01 echo $num1'>'$num2 | bc -l echo $num2'>'$num1 | bc ...
4
votes
2answers
947 views

Float operations with bc not precise?

When I'm performing float operations in shell using bc, the result is not the same if I use a regular calculator. Am I doing something wrong? For example, I need to find a volume of a sphere. User ...
0
votes
1answer
614 views

If else statement involving two numbers in scientific notation [duplicate]

I have two numbers in scientific notation and I want to do some comparison between them in an if statement in bash. While doing so, I am getting error like bwlow: E.g: bash-4.2$ a=10e-12 bash-4.2$ b=...
1
vote
1answer
240 views

How to express floating point expressions in bash scripts

Why does a2=100. echo 1.1*$a2|bc work on the terminal, but the 3 variants in the following script don't: a2=100. echo " 1.1*$a2|bc $(1.1*$a2|bc) $((1.1*$a2|bc)) ">x.sh
2
votes
2answers
749 views

Why do newer versions of awk print large integers instead of decimals?

I often use the awk (gawk) calculator: calc(){ awk "BEGIN{ print $* }" ;} In Ubuntu 14.04, it output big numbers in standard form, e.g. $ calc 56777654409823*4674990588446667952594759939814064128 2....
1
vote
1answer
2k views

Bash script how to accept single or double digit number and make it 2 digit

I have a following simple extract from my script which is strangely stuck up for a particular inputs. echo -e "Enter the Day of the Month : \c " read input_day printf -v input_day '%02d' "$...
18
votes
3answers
34k views

How to format floating point number with exactly 2 significant digits in bash?

I want to print the floating point number with exactly two significant digits in bash (maybe using a common tool like awk, bc, dc, perl etc.). Examples: 76543 should be printed as 76000 0.0076543 ...
5
votes
1answer
20k views

Is it possible to get a decimal output from doing division in Bash? [duplicate]

Basically in Bash, what I'm trying to do is take a input of seconds from a user and find the hours. So basically if the user enter 35 the output should be 0.00972222. But bash gives me is a zero. ...
1
vote
1answer
2k views

comparing decimal point values in if statement

Today I was trying to compare two values and surprised what I saw. I didn't find any good suggestion anywhere. Could any one please help? if [ 10.94 -gt 10 ] then echo True else echo False fi I ...
2
votes
2answers
1k views

Display integral in scientific notation?

I have an integral value: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 2400000 I assign it to a shell variable: CPU_FREQ=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) I ...
1
vote
1answer
174 views

Unix awk decimal export in pipe

I'm struggling to adapt a script, which loops through a large number of individual files (subj_id), and prints out the value of $4 in a specified line. Text file contains lines # Measure Brain, ICV, ...
1
vote
3answers
845 views

Formatting from Decimal to Exponential

I have a data file abc.txt in the following format: BALT 1 54.500 -161.070 3.95863757 0.01691576 BARM 2 -9.200 67.120 4.07529868 0.01951653 BKSR 3 43.830 142.520 4.08919819 0.00587340 I ...
7
votes
4answers
5k views

Weird float rounding behavior with printf

I've read some answers on this site and found the printf rounding desirable. However when I used it in practice, a subtle bug led me to the following behavior: $ echo 197.5 | xargs printf '%.0f' 198 ...
5
votes
1answer
880 views

How to compare float values in a shell script?

I need to alert if my load average is more than 10. I could do it like this if my awk command returned an integer: declare -i MAX_LOAD=10 declare -i L1=`cat /proc/loadavg | awk {'print $1'}` if [ $...
1
vote
1answer
1k views

How to do float operation in Shell script? [duplicate]

time_value=$(($large / 1000)) $large could be 60 or 57. I'm expecting 57/1000=0.057. But I'm getting 0. So, is there any way to do this?
3
votes
4answers
850 views

Convert floating point numbers to decimal numbers

I have several 'ascii' tables in a directory, some of them have numbers expressed in decimal and some others ones in floating point, as follow: 1 1 1423 1 2 1589 1 3 0.85e 5 1 4 0.89e 4 1 5 8796 ... ...
11
votes
4answers
12k views

bash loop with 0.02 increment

I want to make a for loop in bash with 0.02 as increments I tried for ((i=4.00;i<5.42;i+=0.02)) do commands done but it didn't work.
0
votes
1answer
65 views

sum over floating points of the form 3.016e-06 using awk

I want to sum over floats of the form: 3.016e-06 The floats are saved in a files called S_3x3.txt S_4x4.txt ... S_8x8.txt My code sums only the first integer. Instead of 3.016e-06 + 4.022e-06 it ...
1
vote
2answers
2k views

Copy Single Value from a file to a variable and perform arithmetic over it? [duplicate]

Suppose we have a file like 'abc.txt' which has a single value 123456 and file 'xyz.txt' which also has a single value like 654321. I want to store these values form the file to some shell variable ...
3
votes
1answer
313 views

Approximating a floating point number with correct rounding off

How can I approximate a floating point number using shell-script (say, up to 4 digits after the decimal point)? I have two examples: A=1.2345678 and B=1.2345678E-05. So I would like to get A=1....
2
votes
2answers
128 views

Add a number in a huge ASCII file

Background: (1) Here is a screen capture of a part of my ascii file (over 600Mb): (1.1) Here is a part of the code: 0, 0, 0, 0, 0, 0, 0, 0, 3.043678e-05, 3.661498e-05, 2.070347e-05, 2.47175e-...
3
votes
3answers
764 views

Shell script to move files if certain percentage of lines contain a certain string

I am working on a shell script to move files if certain percentage of the lines contain a certain string. I've got ~2000 files in a directory that each contain a single column of data. The number of ...