You are not logged in.

#1 2011-12-30 10:59:43

Manifold
Member
Registered: 2006-08-16
Posts: 64

[SOLVED] bc and the decimal point

Hello,

I've been trying out bc today and I've come across something:

If, for example, I try and calculate 1/10 in bc (whilst setting scale to, say, 5), I'll get .10000. Is there some way to always display the number to the left of the decimal point, even if it's a zero (i.e. 0.10000)? 5/2 will get 2.50000, which makes sense.

Thanks for your help.

Last edited by Manifold (2011-12-30 14:40:30)

Offline

#2 2011-12-30 13:11:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] bc and the decimal point

Yikes, I just tried to read the bc man page ... not the best is it?

I've been a longtime R user.  R is a bit bulkier than bc, but if you're doing anything beyond quick arithmetic I think it would pay off to use R.  And R is *very* well documented.

Otherwise best of luck.

Last edited by Trilby (2011-12-30 13:11:22)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2011-12-30 13:21:32

Manifold
Member
Registered: 2006-08-16
Posts: 64

Re: [SOLVED] bc and the decimal point

Well, I am doing very simple arithmetic. It just so happens that what I want to do concerns fractional quantities and bash arithmetic doesn't like that. I guess I could use R, but ideally I would use bc for its large installation presence...

Last edited by Manifold (2011-12-30 13:22:06)

Offline

#4 2011-12-30 14:30:11

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] bc and the decimal point

Offline

#5 2011-12-30 14:40:12

Manifold
Member
Registered: 2006-08-16
Posts: 64

Re: [SOLVED] bc and the decimal point

I did something quite similar, but using a bash script to concatene a '0' in front of the decimal place. I just thought there was a simple variable to set that I'd missed but I guess not. I wonder what the design purpose of missing out the 0 on the left hand side of a decimal place is.

Offline

#6 2012-01-01 19:11:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] bc and the decimal point

Seems that awk can be a nice calculator too: https://bbs.archlinux.org/viewtopic.php … 64#p717764

[karol@black ~]$ calc 1/10
0.1

It should have a wide installation base too.

Offline

#7 2012-01-02 11:03:02

Manifold
Member
Registered: 2006-08-16
Posts: 64

Re: [SOLVED] bc and the decimal point

That's a pretty nifty trick. Thanks!

Offline

Board footer

Powered by FluxBB