How to get decimal value from division in fish shell

math 5/2 returns 2.

I want 2.5 - how to get decimal values?

+4
source share
3 answers

You can "force" mathreturn the default values ​​- use the parameter -lfor bc:

$ math 5/2
2

$ function bc
      command bc -l $argv
  end

$ math 5/2
2.50000000000000000000
+2
source

Add this to one of the config.fish files

set -x BC_ENV_ARGS ~/.bc.cfg

Then create a .bc.cfg file to tell a lot of decimal places to display

echo "scale = 5" >> .bc.cfg

This will:

math 5/2

2,50000

+2
source

you need to force floating point division instead of integer division

math 5/2.0

0
source

Source: https://habr.com/ru/post/1532151/


All Articles