ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: halloleo on January 28, 2022, 01:31:25 AM

Title: How to limit writing out ExposureCompensation to 2 significant digits?
Post by: halloleo on January 28, 2022, 01:31:25 AM
Hi there

For exposure bracketed sequences I'm using exiftool to embed the ExposureCompensation tag in the filename. With the '<' syntax like:
    $ exiftool '-FileName<%f_EV${ExposureCompensation;}.%e' .
this is blazingly fast! Very cool!

However I have some strange ExposureCompensation values like "+0.996" and "-0.996". They are cearly meant to be +1 and -1. (The image file provider -- CameraPixels app on iOS -- seems to do something wrong here).

To cut a long story short, in the renamed filename I would like to round the  ExposureCompensation values to 2 significant digits, so that 0.996 becomes 1. Is this possible with the '<' syntax?

Many thanks for any pointers!
Title: Re: How to limit writing out ExposureCompensation to 2 significant digits?
Post by: Phil Harvey on January 28, 2022, 07:32:39 AM
There are a number of ways to round values.  One way is to use sprintf.  To get 2 significant digits with a sign, you would use %+.2g, like this:

exiftool '-FileName<%f_EV${ExposureCompensation#;$_=sprintf("%+.2g",$_)}.%e' .

Here I have added a "#" to start from the numerical value (eg. 0.66666) instead of the converted value (eg. +2/3) since most ExposureCompensation tags are returned as fractions.

- Phil
Title: Re: How to limit writing out ExposureCompensation to 2 significant digits?
Post by: halloleo on January 29, 2022, 07:56:08 AM
Work brilliantly, Phil.

Thanks a lot for spelling out the details.

I really appreciate it.

Leo