Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash float operation

bc -l <<< '10/3' # Fast way
3.33333333333333333333
bc <<< 'scale=2; 10/3' #Define also how many decimals to take in scale
3.33
Comment

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 :: ubuntu set desktop as default bashrc 
Shell :: how to avoid some files changes to not come in git status 
Shell :: dig +noall +answer 
Shell :: eslint check 
Shell :: check login info on mac os 
Shell :: snap scrcpy 
Shell :: mac theme ubuntu terminal 
Shell :: how to find device model of laptop on linux 
Shell :: Optimize images like Photoshop Bulk 
Shell :: how create new git branch 
Shell :: create cat document ubuntu 
Shell :: turn off wiregurad 
Shell :: linux create file without content 
Shell :: bash read file into array 
Shell :: curl detailed response 
Shell :: cat stands for in linux 
Shell :: unmount linux 
Shell :: how to locate a file in linux 
Shell :: how to remove first colum froim file linux 
Shell :: raspberry remote 
Shell :: powershell get disk space remote computer 
Shell :: ansible ad hoc file module 
Shell :: gsed comand store file 
Shell :: Use R markdown in github README 
Shell :: gcloud add role to service account 
Shell :: vim colorscheme 
Shell :: ssh key exchange 
Shell :: .m2 folder in unix 
Shell :: docker-compose.yml ubuntu 
Shell :: kill background job 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =