Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash float

bc <<< '0.3333+0.6666' # Get sum of floats in bash.
0.99			#Same for Substraction and Multiplication
bc -l <<< '10/3' # Fast way to get division
3.33333333333333333333
bc <<< 'scale=2; 10/3' #Define also how many decimals to take in scale
3.33
Comment

float calculation bash

$ printf %.10f
 "$((10**9 * 20/7))e-9"   # many shells. Not mksh.
$ echo "$((20.0/7))"                       # (ksh93/zsh/yash, some bash)
$ awk "BEGIN {print (20+5)/2}"
$ zcalc
$ bc <<< 20+5/2
$ bc <<< "scale=4; (20+5)/2"
$ dc <<< "4 k 20 5 + 2 / p"
$ expr 20 + 5
$ calc 2 + 4
$ node -pe 20+5/2  # Uses the power of JavaScript, e.g. : node -pe 20+5/Math.PI
$ echo 20 5 2 / + p | dc 
$ echo 4 k 20 5 2 / + p | dc 
$ perl -E "say 20+5/2"
$ python -c "print(20+5/2)"
$ python -c "print(20+5/2.0)"
$ clisp -x "(+ 2 2)"
$ lua -e "print(20+5/2)"
$ php -r 'echo 20+5/2;'
$ ruby -e 'p 20+5/2'
$ ruby -e 'p 20+5/2.0'
$ guile -c '(display (+ 20 (/ 5 2)))'
$ guile -c '(display (+ 20 (/ 5 2.0)))'
$ slsh -e 'printf("%f",20+5/2)'
$ slsh -e 'printf("%f",20+5/2.0)'
$ tclsh <<< 'puts [expr 20+5/2]'
$ tclsh <<< 'puts [expr 20+5/2.0]'
$ sqlite3 <<< 'select 20+5/2;'
$ sqlite3 <<< 'select 20+5/2.0;'
$ echo 'select 1 + 1;' | sqlite3 
$ psql -tAc 'select 1+1'
$ R -q -e 'print(sd(rnorm(1000)))'
$ r -e 'cat(pi^2, "
")'
$ r -e 'print(sum(1:100))'
$ smjs
$ jspl
$ gs -q  <<< "5 2 div 20 add  ="
Comment

PREVIOUS NEXT
Code Example
Shell :: how to go to a previous commit state 
Shell :: create user in linux 
Shell :: tar: Cowardly refusing to create an empty archive 
Shell :: exa ls command 
Shell :: Why double tapping icon doesnt minimize in ubuntu 
Shell :: vimeo status video 
Shell :: wc - l 
Shell :: unix timestamp bash 
Shell :: see all drives linuix 
Shell :: git clone with subdirectories 
Shell :: Failed to start uWSGI Emperor Service 
Shell :: git update branch from master 
Shell :: magento install with composer 
Shell :: cli50 install with pip3 
Shell :: linux command find executable 
Shell :: zsh: command not found: sublime 
Shell :: mqtt client ubuntu console 
Shell :: how to open ubuntu file in visual studio 
Shell :: github as database 
Shell :: git use stash on another computer 
Shell :: github checkout 
Shell :: run powershell script by clicking 
Shell :: git reset commit before file 
Shell :: how to save ssh keygen How to add ssh keys to a specific user in linux? 
Shell :: Docker: Copying files from Docker container to host 
Shell :: powershell import-certificate trusted publisher 
Shell :: odoo 14 install ubuntu 20.04 
Shell :: Create and Switch To a New Branch in git command 
Shell :: installing dbeaver 
Shell :: mongo remove collection 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =