azbob wrote: ↑Sun Mar 21, 2021 3:26 am
FCI:
Code: Select all
Microsoft Windows 10 Home
Microsoft Windows NT 10.0.19041.0
64-bit Operating System
iMacros Browser (x86) Version 12.6.505.4525
Released on 11/8/19
Licensed Product: iMacros Enterprise Edition
PM: V29
Hi,
I am trying to display decimal field without leading zero, ie: " .00 instead of 0.00"
It works in "MNTH" field but not in the "Comp_Sold" field.
Here are the prompts:
>
PROMPT 1:
Code: Select all
Monthly_Numbers:
Mnthly1: .08
Mnthly2: 1
>
PROMPT 2:
Code: Select all
Num_Sold: 10
MNTH: .8
Comp_Sold: 0.8
My question is if MNTH: displays ".8" , Why does Comp_Sold display " 0.8" since it appears that the all "SET Comp_Sold" line does in this case is set Comp_Sold to whatever is in MNTH (or Mnthly2. if I set Num_Sold to a number >= 12).
Code: Select all
VERSION BUILD=12.6.505.4525
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE NO
'SET Num_Sold to number <12 for decimal (<1) or SET to number >12 for whole number ( >=1) in Comp_Sold
SET Num_Sold 10
'Determine if monthly number is displayed as decimal or whole number
'Display Decimal when yearly total number is less than 12 per year
SET Mnthly1 EVAL("var w,x,y,z; w=(\"{{Num_Sold}}\" / 12); x=(w.toFixed(1)); x;")
'Display whole number when yearly total is 12 or more per year
SET Mnthly2 EVAL("var x,y; x=(\"{{Num_Sold}}\" / 12); y=(Math.round(x)); y;")
PROMPT Monthly_Numbers:<BR>Mnthly1:<SP>{{Mnthly1}}<BR>Mnthly2:<SP>{{Mnthly2}}
'If decimal just display numbers after decimal point .00 not 0.00
SET MNTH EVAL("var x,y,z; x=(\"{{Mnthly1}}\"); z=x.slice(1); z;")
'Determine if MNTH is decimal or not(<1). If so put MNTH into Comp_Sold. If not put Mnthly2 in Comp_Sold
SET Comp_Sold EVAL("if ({{MNTH}} > 0 && {{MNTH}} < 1) {{MNTH}}; else {{Mnthly2}}; ")
PROMPT Num_Sold:<SP>{{Num_Sold}}<BR>MNTH:<SP>{{MNTH}}<BR>Comp_Sold:<SP>{{Comp_Sold}}
I have stared at this too long and tried many iterations, but I can't get Comp_Sold to display the right format.
Thanks
Bob
Fouff-fouff, you are a bit "messy", in your way of "Thinking", ah-ah...! OK, don't get "angry", but "follow me"...!"
First, I will simply repost your Script with just a few Returns...:
Code: Select all
VERSION BUILD=12.6.505.4525
TAB T=1
'TAB CLOSEALLOTHERS
'SET !ERRORIGNORE NO
'SET Num_Sold to number <12 for decimal (<1) or SET to number >12 for whole number ( >=1) in Comp_Sold
SET Num_Sold 10
'Determine if monthly number is displayed as decimal or whole number
'Display Decimal when yearly total number is less than 12 per year
SET Mnthly1 EVAL("var w,x,y,z; w=(\"{{Num_Sold}}\" / 12); x=(w.toFixed(1)); x;")
'Display whole number when yearly total is 12 or more per year
SET Mnthly2 EVAL("var x,y; x=(\"{{Num_Sold}}\" / 12); y=(Math.round(x)); y;")
PROMPT Monthly_Numbers:<BR>Mnthly1:<SP>{{Mnthly1}}<BR>Mnthly2:<SP>{{Mnthly2}}
'If decimal just display numbers after decimal point .00 not 0.00
SET MNTH EVAL("var x,y,z; x=(\"{{Mnthly1}}\"); z=x.slice(1); z;")
'Determine if MNTH is decimal or not(<1). If so put MNTH into Comp_Sold. If not put Mnthly2 in Comp_Sold
SET Comp_Sold EVAL("if ({{MNTH}} > 0 && {{MNTH}} < 1) {{MNTH}}; else {{Mnthly2}}; ")
PROMPT Num_Sold:<SP>{{Num_Sold}}<BR>MNTH:<SP>{{MNTH}}<BR>Comp_Sold:<SP>{{Comp_Sold}}
=> Re-ouf-ouf, I had some some "Difficulty" reading your one-Block Script, and 4 Vars you define with more or less but still 4 different Naming Conventions..., hum, or 3 actually, but still confusing anyway...
I won't try (for now at least) to debug your Script, I'm pretty confident you'll find the Solution by yourself, if you follow my "little Advice", and use "my" Syntax...
>>>
=> Better...:
Code: Select all
'Determine if monthly number is displayed as decimal or whole number
'Display Decimal when yearly total number is less than 12 per year
'SET Mnthly1 EVAL("var w,x,y,z; w=(\"{{Num_Sold}}\" / 12); x=(w.toFixed(1)); x;")
SET Monthly_Nb_1 EVAL("var ns='{{Num_Sold}}'; var x,y,z; x=ns/12; z=x.toFixed(1); z;")
>
=> Better...:
Code: Select all
'Display whole number when yearly total is 12 or more per year
'SET Mnthly2 EVAL("var x,y; x=(\"{{Num_Sold}}\" / 12); y=(Math.round(x)); y;")
SET Monthly_Nb_2 EVAL("var ns='{{Num_Sold}}'; var x,y,z; x=ns/12; z=Math.round(x); z;")
PROMPT Monthly_Numbers:<BR>Monthly_Nb_1:<SP>_{{Monthly_Nb_1}}_<BR>Monthly_Nb_2:<SP>_{{Monthly_Nb_2}}_
(+ 'PROMPT' with Underscores to display Vars...!!
)
>
=> Better...:
Code: Select all
'If decimal just display numbers after decimal point .00 not 0.00
'SET MNTH EVAL("var x,y,z; x=(\"{{Mnthly1}}\"); z=x.slice(1); z;")
SET Monthly_Nb_1_Dec EVAL("var m1='{{Mnthly1}}'; var x,y,z; z=m1.slice(1); z;")
Hum..., 'slice()' is a 'String' Method, not "meant" for Numbers...
But OK, "luckily" for you, iMacros has "difficulties" with Vars, especially in 'EVAL()' and finally treat them all as 'String', so you are fine, ah-ah...!
And re-hum, "If decimal => whatever", but you don't have any 'if' Condition (and even less 'else'), so you are truncating the first Char of all Input Strings/Nb's in that 'EVAL()'... Not sure that's the Result you want...
>
=> Orig..:
Code: Select all
'Determine if MNTH is decimal or not(<1). If so put MNTH into Comp_Sold. If not put Mnthly2 in Comp_Sold
SET Comp_Sold EVAL("if ({{MNTH}} > 0 && {{MNTH}} < 1) {{MNTH}}; else {{Mnthly2}}; ")
PROMPT Num_Sold:<SP>{{Num_Sold}}<BR>MNTH:<SP>{{MNTH}}<BR>Comp_Sold:<SP>{{Comp_Sold}}
=> Hum..., I don't know this (simplified) 'if'/'else' Syntax... But OK, you have some 'PROMPT' to follow your Vars, I guess you've already checked that you don't get any "_Undefined_" in the 'PROMPT'... (for your "Comp_Sold" Var...).
=> Better anyway...:
Code: Select all
'Determine if MNTH is decimal or not(<1). If so put MNTH into Comp_Sold. If not put Mnthly2 in Comp_Sold
'SET Comp_Sold EVAL("if ({{MNTH}} > 0 && {{MNTH}} < 1) {{MNTH}}; else {{Mnthly2}}; ")
SET Comp_Sold EVAL("var m1='{{Monthly_Nb_1}}', m2='{{Monthly_Nb_2}}', m1d='{{Monthly_Nb_1_Dec}}'; var x,y,z; if((m1d>0)&&(m1d<1)){z=m1d;} else{z=m2;}; z;")
PROMPT Num_Sold:<SP>{{Num_Sold}}<BR>MNTH:<SP>{{MNTH}}<BR>Comp_Sold:<SP>{{Comp_Sold}}
OK, I didn't correct your last 'PROMPT', you know how "now"...
And integrate all Parts together to debug your Script...
+ One final 'PROMPT' with all Vars used in your Script...!
(=> Notice the '_' (Underscore) I re-added to your/my Script around Vars in a 'PROMPT', very useful, trust me, ah-ah...!
)
>>>
And "again" I didn't run your Script, only vaguely "mentally", and I don't know the 'if'/'else' Syntax you used, so hum..., I didn't "try my best", but I honestly think that if you follow my "Principles", you should find the Sol by yourself... (and probably won't ever need any Help from me or the Forum anymore, ah-ah...!)
And mini-Remark, but it took me more than 1 Hour to prepare and post this Reply, while I would have probably found "the" Solution to your Pb in less than 5 Min if I had run your Script and done the Debugging myself, but I think it's more useful to you (and to other Users) if you find the Sol by yourself...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...