Format accepting variable?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Format accepting variable?

Post by Phil Pendlebury » Tue Nov 30, 2021 12:28 pm

Hi there,

I am trying to give an option in a dialog as to how many decimal places to format. So:

Code: Select all

Format>%.2n,mill_calc,fmill_calc
Is 2 decimal places.

Ideally what I would like to do is (normally "dp" is set by dialog input but in this example we will just set it to value 5):

Code: Select all

Let>dp=5

Code: Select all

Format>%.%dp%n,mill_calc,fmill_calc
But the result ends up blank.

I am guessing that is not possible to use a variable in the format command in this way.

Any thoughts on this? :-)
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Format accepting variable?

Post by Phil Pendlebury » Tue Nov 30, 2021 12:58 pm

OK disregard this please, as I now realise that format does not affect calculations to decimal places, only the display of the number. Sorry, I was not aware of the format option previously and have not used it before.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Format accepting variable?

Post by Phil Pendlebury » Tue Nov 30, 2021 1:21 pm

Of course what I needed was:

Code: Select all

 VBEval>Round("%mill_calc%","%frame_rate_dp%"),fmill_calc
Phil Pendlebury - Linktree

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Format accepting variable?

Post by Dorian (MJT support) » Tue Nov 30, 2021 2:08 pm

I tried all manner of ways but the % seemed to cause problems, but I finally managed to get there with Format. It looks a bit messy but it works :

Code: Select all

let>mill_calc=1
Let>dp=5
let>pc=%
Let>FormString=%pc%.%dp%n
Format>%FormString%,mill_calc,fmill_calc
mdl>fmill_calc
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Format accepting variable?

Post by Phil Pendlebury » Tue Nov 30, 2021 4:58 pm

Nice one Dorian, I thought I had tried that too earlier but must have missed it.

However, as mentioned, the thing I didn't realise is that format only "formats" the number "Doh".

And what I wanted to do was change the actual number of decimal places as a calculation.

I am sure this will be useful for any future searches one the subject though.

Image
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts