Search code examples
stringbashreplaceexifoperation

floating-point operations with bash


how can I transform the string "620/100" into "6.2" in a bash script

The context of my question is about image processing. EXIF data are coding the focal length in fractional format, while I need the corresponding decimal string.

Thanks for helping, Olivier


Solution

  • Use bc -l

    bc -l <<< "scale=2; 620/100"
    6.20
    

    OR awk:

    awk 'BEGIN{printf "%.2f\n", (620/100)}'
    6.20