bash + how to calculate very long numbers in bash?

7,125

Use bc ("an arbitrary precision calculator language"):

param=$(bc <<< '3247238523785623478565 + 53453453252345346534563412634')
Share:
7,125

Related videos on Youtube

maihabunash
Author by

maihabunash

I am 17 years old and love to develop

Updated on September 18, 2022

Comments

  • maihabunash
    maihabunash almost 2 years

    How to calculate very long numbers in bash?

    param=$(( 3247238523785623478565 + 53453453252345346534563412634 ))
    
    echo $param
    3420247196502465471
    

    as we see here, this isn't the right answer because of the limit of integer numbers.

    • Marco
      Marco about 9 years
    • philwalk
      philwalk over 6 years
      the link above "How do integer & float" does not say anything about long numbers in bash. Most of the answers depend on tools other than bash (not always an option). so this is not a duplicate of that