Round to n-places

Started by irinaonline, August 18, 2019, 04:22:17 PM

Previous topic - Next topic

irinaonline

I am writing GPS speed, altitude, and other statistical stuff in my keywords. As the values have multiple places behind the comma, I would like to round them to n-places. If rounding is not possible, how can I say x-numbers after the decimal point? Would the command be different if I just omit every number after the decimal point?

StarGeek

It can be done, but the procedure might depend upon the rest of your command.

The code to be used would be $_=sprintf('FMT',$_) where FMT is a perl printf style format string.  I believe that perl printf has a few differences than other types of printf, such as C, so if you want to do something other than the round to decimal place that I detail below, you might have to be careful.

To global round to 2 decimal places, you would add this to your command
-api "filter=$_=sprintf('%.2f',$_)"
Though this will have problems if your command is dealing with tags that aren't just numbers.

To edit specific tags, as in your example of copying to Keywords, you would do something like this
"-Keywords<${GPSSpeed;$_=sprintf('%.2f',$_)}"
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

irinaonline

it doesn't seem, i get the syntax ever right, as i get always parts of the syntax in the tag.

i tried now ${GPS:GPSAltitude#;s/:.*//} and ${GPSSpeed#;s/:.*//} to remove all digits behind the dot, but even this does not work. any idea of an easy syntax for dos?

irinaonline

i ended up finally with the command -api filter=""s/\s*\..*//"" which just omits everthing beginning with a .