Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a decimal number when dividing in bc?

Tags:

unix

bc

I need 'bc' to divide a number and give me not only the floor but also the remainder. For instance 'bc' gives me '2' if I do '5/2'. I'd really want something like '2.5'

Maybe this isn't even possible?

like image 224
EhevuTov Avatar asked Apr 25 '12 21:04

EhevuTov


1 Answers

scale = 20

It sets the number of decimal places.

$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
355/113
3
scale=20
355/113
3.14159292035398230088
quit
$
like image 80
Jonathan Leffler Avatar answered Oct 14 '22 21:10

Jonathan Leffler