Argument Like |cast:int to not 'round up' to next digit

Started by Darius1968, June 17, 2023, 07:48:08 AM

Previous topic - Next topic

Darius1968

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. 

sinus

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.
Best wishes from Switzerland! :-)
Markus

axel.hennig

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?

thrinn

You should be able to use this trick:
{File.AT.TestDarius.IMDB Rating|math:add,0}If you look at the help for math, 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.
Thorsten
Win 10 / 64, IMatch 2018, IMA

axel.hennig


Darius1968

#5
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! 

sinus

Finally, Darius, you got it! Cool!  :)

I use these math argument quite a lot, they are very useful solving a lot of problems. 
Best wishes from Switzerland! :-)
Markus