Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum with decimal 2

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
Hi, im trying to get, add several numbers such as:

let C=$A+$B

where variables have values as:
A=00,000000011
B=00,003481000

when I execute this, I have this output:

let: C=00,000000011+00,003481000: value too great for base (error token is "00000001"....

I know it interprets as an octal value.
Then, I've put:
let C=10#$A+10#$B

I put 10# before the variables for interpret decimal value.
I have this output:
C=10#00,000000011+10#00,043083000: value too great for base (error token is "00000001"....

How I can make this sum, with bash scripting?

Thanks.
 
Hi

Are you sure your locale setting has comma ( , ) as decimal separator ? And [tt]bash[/tt] does arithmetic operations only with integers.
Code:
[blue]master #[/blue] A=00.000000011

[blue]master #[/blue] B=00.003481000

[blue]master #[/blue] echo "$A+$B" | bc
.003481011

Feherke.
 
Hi.
Yes, my locale setting has comma as decimal separator. These values are extracted of a file. How I can make this sum if the numbers have comma and nonpoint?

Thanks.
 
Unfortunately it seems that bc is not locale sensitive.

You could be tricky like this:

[tt]$ A=00,000000011
$ B=00,003481000
$ echo "$A+$B" | tr , . | bc | tr . ,
,003481011
$[/tt]


Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top