Monday-question: math-variable count with decimal-numbers

Started by sinus, October 16, 2023, 09:02:12 AM

Previous topic - Next topic

sinus

It is again monday. My brain is not here completely ... 

My question is embarrassing for me:
I want to calculate 30.5 percent (in effect, several different percentages) of a number using the math variables.
The final result should be a number, preferably rounded to a whole number.

I can't do that because of the decimals.
I wanted to make a diversion with div and mul, but that doesn't work either because I haven't figured out how to divide a number by 7.3, for example. (It's no problem to divide by a whole number, the problem is divide through a decimal-number).

So, my question finally, 
what is the easiest way to calculate e.g. 30.5 percent of a number with the result of a rounded number.

I have tried this with OID as an example:
{File.OID|math:xxxx} and failed.

I have tried to search hier in the forum and of course in the help, but found nothing. Maybe also because it is monday ...  :-[
Best wishes from Switzerland! :-)
Markus

Mario

The problem are , and . which can both be decimal separators or variable parameter separators.
IMatch is not Excel, not everything you may want to do can work.

To deal with that, scale by 100. Don't multiply by 35.5 (or 35,5) but by 355 and divide by 1000 instead of 100. Or by 3550 and 1000, if you need more precision.

The first variable returns the precise value with two decimal digits. The second uses cast:int to round the value.
See the variable help on match and decimals for details.

{File.AT.Notes.Value_I|math:mul,355;math:div,1000,2}
{File.AT.Notes.Value_I|math:mul,355;math:div,1000,2;cast:int}
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Mario, that is great, thanks a lot!  :) You made my day!

I should have known this, but ...

And btw, IMatch is not Excel, that is true, but IMatch can do a lot and I love your math-functions (and variables!), though of course Excel is specialized on math, and hence is is normal, that in this area it can do more.

But IMatch is IMatch and it is great.  :)
Best wishes from Switzerland! :-)
Markus

StanRohrer

I don't intend to hijack a thread - but it appears this discussion is done.

Thank you guys so much for this brief discussion! It provided just enough info for me to solve my math problem where I was wanting to calculate print dimensions from pixels and resolution. I was trying to get 2 decimal places for inches. I had missed the {,decimals} argument to the math:div function.

Default print size: {File.Width|math;math:div,{File.MD.Photoshop::Resolution\0\XResolution\0},2} x {File.Height|math;math:div,{File.MD.Photoshop::Resolution\4\YResolution\0},2} inches.

sinus

Hi Stan

So this is a positive side-effect for you.  :D 
Very good.

I just tried your variable with VarToy and it works perfect. 
Variables, and of course math, are very strong and we can do a lot. But sometimes, forget a minus or a semicolon and nothing works.  8) And I tend to create complicated variables. 

Fine, your problem is solved and mine also. Thanks to Mario, he knows (almos) everything. ;D

Best wishes from Switzerland! :-)
Markus