FORMAT> issue

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

FORMAT> issue

Post by mightycpa » Wed Oct 18, 2017 9:32 pm

I need to format any positive number to a length of 15, always including two decimal places, with no additional adornments, like this:

123456789012.45

a) What is going on with this code?

Code: Select all

Let>v_sumdr=789012.45
//Format>%.2n,%v_sumdr%,v_sum1
Format>%15d,%v_sumdr%,v_sum2
//v_sum2 yields a padded zero
MessageModal>%v_sum2%   
b) can FORMAT do the job, or do I have to write my own function?
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: FORMAT> issue

Post by Marcus Tettmar » Thu Oct 19, 2017 9:14 am

Don't think Format will do what you want. I'm a little unsure what you want to do. Does your source data already have two decimal places? Do you just mean you want to prepad the number with zeros? i.e. if you start with 709012.45 are you wanting to end up with 0000000709012.45 ?

If so you could just do:

Code: Select all

Let>num_in=709012.45
VBEval>Right("00000000000000" & "%num_in%",15),num_out
Of course any input that is larger than 15 digits will be truncated, losing the significant digits.

Hence why I need to ask what you are trying to achieve.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: FORMAT> issue

Post by mightycpa » Thu Oct 19, 2017 7:19 pm

No, I need to prepad with spaces, and no, the amount does not always have two decimals. It might be 1.1 or 1234

In the end, I need it to be a string of length 15, with two decimals on the end.

I had already come to the conclusion that FORMAT wouldn't help, so I wrote something that works.

As to "what is going on with this code?" again, I should have been more clear, but run this code:

Code: Select all

Let>v_sumdr=789012.45
//Format>%.2n,%v_sumdr%,v_sum1
Format>%15d,%v_sumdr%,v_sum2
//v_sum2 yields a padded zero
MessageModal>%v_sum2%
and see if you are as surprised by the results as I am.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: FORMAT> issue

Post by JRL » Thu Oct 19, 2017 8:49 pm

Doesn't seem to like the decimal point.

Code: Select all

Let>v_sumdr=789012
//Format>%.2n,%v_sumdr%,v_sum1
Format>%15d,%v_sumdr%,v_sum2
//v_sum2 yields a padded zero
MessageModal>%v_sum2%

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: FORMAT> issue

Post by mightycpa » Thu Oct 19, 2017 9:16 pm

Good catch, JRL!
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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