bash的浮点运算 [英] floating-point operations with bash

查看:101
本文介绍了bash的浮点运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在bash脚本中将字符串"620/100"转换为"6.2"

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

我的问题的背景与图像处理有关. EXIF数据以小数格式编码焦距,而我需要相应的十进制字符串.

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

推荐答案

使用bc -l

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

或awk:

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

这篇关于bash的浮点运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆