bc scale problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bc scale problem
# 1  
Old 09-16-2011
bc scale problem

Dear Experts,

I want to use bc to do some multiplication and return me a value with number of decimal places defined by myself.

For example:
Code:
echo "scale=10; 1.65*7" | bc

returns me:
Code:
11.55

But what I really want is to have is a result with 10 digits after the point which should look like:
Code:
11.5500000000

But "scale" just doesn't work here. And, if I want to have result without decimal place, for 11.55, it should return me the result like:
Code:
12

Could I achieve these without the help of other command. I know I could pipe the result to awk or another bc (by division for which scale works), but I just interested in if a single bc with some special option can do it simply?

I would greatly appreciate to your kind help!

Last edited by cristalp; 09-16-2011 at 02:38 PM..
# 2  
Old 09-16-2011
Hi, try:
Code:
echo "scale=10; 1.65*7/1" | bc

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 09-16-2011
Anothey way would be...
Code:
echo "1.6500000000*7" | bc

# 4  
Old 09-16-2011
Why does that work for multiplication but not division?
# 5  
Old 09-16-2011
Quote:
Originally Posted by Corona688
Why does that work for multiplication but not division?
Because divison works exclusively off the internal scale which is initialized to zero by default...but for multiplication both the internal scale and the scale of the factors comes into play...so the scale of x*y is the larger of either the internal scale or the scale of the factors...x or y.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Programming

Isosurface and a 2D figure with the same scale and origin using mayavi

I am using mayavi to plot an iso surface from a 3D array s using the following piece of code: src = mlab.pipeline.scalar_field(s) fig=mlab.pipeline.iso_surface(src, color=(1.0,0.0,0.0), contours=, opacity=0.3) mlab.pipeline.iso_surface(src, color=(0.0,1.0,1.0),contours=, opacity=0.3) Then... (0 Replies)
Discussion started by: jaldo0805
0 Replies

2. UNIX for Dummies Questions & Answers

Any company running large scale grid platform still

Hi buddy, I would like to know are there any company still running large scale grid platform like Parabon? Parabon is the only company running such kind of platform and purchasing CPU power. Is that right? Thanks, Colapig (0 Replies)
Discussion started by: colapig
0 Replies

3. Solaris

unable to allocate enough cells for gray scale

Hi, I tried to install a software (written in C) and run it on a sun machine. It is displaying the error: unable to allocate enough cells for gray scale. I closed all other apllications and set background to black to minimize usage of cells. But it is diaplaying the same error. Plz help... (1 Reply)
Discussion started by: raz
1 Replies
Login or Register to Ask a Question