photools.com Community

IMatch Discussion Boards => General Discussion and Questions => Topic started by: Darius1968 on June 17, 2023, 07:48:08 AM

Title: Argument Like |cast:int to not 'round up' to next digit
Post by: Darius1968 on June 17, 2023, 07:48:08 AM
Consider that I have a variable of type:Real, and I want to turn the result into an integer that is not 'rounded up' to the next digit, like this:  
Raw ValueInteger not 'rounded up'
7.47
2.82
8.98
4.34

However, using {File.AT.Video Files.IMDB Rating|cast:int}, my output is 'rounded up' to the next digit, like this: 
Raw ValueFormatted with |cast:int
7.47
2.83
8.99
4.34

So, what argument can I use for the variable to give me output like in the 1st table?  Thanks. 
Title: Re: Argument Like |cast:int to not 'round up' to next digit
Post by: sinus on June 17, 2023, 08:58:50 AM
In the help is a lot written about such things, like:

If you work with real/floating point numbers, specify digits as 2 or more. Else the decimals will be trimmed and, for example, a result like 3.1415926  is retourned as 3.
With 2 digits you'll get 3.14 and with 4 digits you'll get 3.1416

Maybe you can find there a solution.
Title: Re: Argument Like |cast:int to not 'round up' to next digit
Post by: axel.hennig on June 17, 2023, 09:36:43 AM
If it is an IMDB rating my assumption would be that the values are between 0 (including) and 10 (excluding). So just one digit before the decimal point. Maybe you can use substr?
Title: Re: Argument Like |cast:int to not 'round up' to next digit
Post by: thrinn on June 17, 2023, 11:14:16 PM
You should be able to use this trick:
{File.AT.TestDarius.IMDB Rating|math:add,0}If you look at the help for math (https://www.photools.com/help/imatch/var_basics.htm#a_format?dl=h-229), you will find this information:
If you work with real/floating point numbers, specify digits as 2 or more. Else the decimals will be trimmed and, for example, a result like 3.1415926 is returned as 3. With 2 digits you'll get 3.14 and with 4 digits you'll get 3.1416.

Thinking a bit backwards, this means that one can intentionally leave out the digits argument, so that the Real variable is truncated or trimmed. Adding 0 does not change the value, so I think this should work.
Title: Re: Argument Like |cast:int to not 'round up' to next digit
Post by: axel.hennig on June 17, 2023, 11:31:53 PM
That's interesting. Thanks Thorsten.
Title: Re: Argument Like |cast:int to not 'round up' to next digit
Post by: Darius1968 on June 18, 2023, 03:44:33 AM
Thorsten, that is exactly what I came up with!  (After spending some time examining the part of the help file that Markus (and, now, you) quoted)

What it boils down to is that with the math arguments (probably should have been called arithmetic arguments from the get-go), one can add or subtract 0, or one can divide or multiply by 1.  I just divided by 1 ;D

So, thanks to Markus and Thorsten! 
Title: Re: Argument Like |cast:int to not 'round up' to next digit
Post by: sinus on June 18, 2023, 08:36:34 AM
Finally, Darius, you got it! Cool!  :)

I use these math argument quite a lot, they are very useful solving a lot of problems.