MarcomCentral (PTI) and FusionPro User Communities Multiply result of rounding
 Register FAQ Calendar Search Today's Posts Mark Forums Read

#1
June 10th, 2014, 01:17 PM
 david.young Junior Community Member Join Date: Sep 2008 Location: Tucson, AZ Posts: 46
Multiply result of rounding

I've created this rule which fills my first need. Now I need to take the result of this and multiply by 1.5

{
return "<span>" + String("20") + "</span>";
}
{
return "<span>" + String("500") + "</span>";
}
else
{
return "<span>" + (Math.ceil(Field("GIFTAMNT")/5)*5) + "</span>";
}
return "";
#2
June 10th, 2014, 02:23 PM
 Dan Korn FusionPro Senior Engineer / Forum Moderator Join Date: Aug 2008 Location: Chicago, IL Posts: 4,671
Re: Multiply result of rounding

Quote:
 Originally Posted by david.young I've created this rule which fills my first need. Now I need to take the result of this and multiply by 1.5 if (StringToNumber(Field("GIFTAMNT")) < 20.01) { return "" + String("20") + ""; } if (StringToNumber(Field("GIFTAMNT")) > 500) { return "" + String("500") + ""; } else { return "" + (Math.ceil(Field("GIFTAMNT")/5)*5) + ""; } return "";
All those <span> tags do nothing. I would start by getting rid of them, and then write the rule like so:
Code:
```var num = StringToNumber(Field("GIFTAMNT"));
var result = 0;

if (num  < 20.01)
result = 20;
else if (num > 500)
result = 500;
else
result = Math.ceil(num/5)*5;

return result * 1.5;```
Or, more succinctly:
Code:
`return Math.ceil(Math.max(20, Math.min(500, StringToNumber(Field("GIFTAMNT"))))/5)*7.5;`
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
#3
June 10th, 2014, 03:46 PM
 david.young Junior Community Member Join Date: Sep 2008 Location: Tucson, AZ Posts: 46
Re: Multiply result of rounding

Thanks Dan, This does exactly what I needed.

Curious, if the <span> tag does nothing why does the rule wizard put them in when you convert to javascript?
#4
June 10th, 2014, 03:59 PM
 Dan Korn FusionPro Senior Engineer / Forum Moderator Join Date: Aug 2008 Location: Chicago, IL Posts: 4,671
Re: Multiply result of rounding

Quote:
 Originally Posted by david.young Thanks Dan, This does exactly what I needed. Curious, if the tag does nothing why does the rule wizard put them in when you convert to javascript?
The Drag-and-Drop Rule Wizard puts in those tags because it *might* be changing the font, or some other style attribute of the text, in which case there will be other formatting tags directly following the <span> tag. But if there are no style changes, it's basically superfluous. I suppose the "Convert to JavaScript" logic could be changed to not bother putting out an empty <span> tag when there's no style change, but that Drag-and-Drop editor was not designed with the goal of producing simple converted JavaScript code. In any case, if you're simply doing a basic "if-else" chain and returning plain text without any formatting tags, I think it's just as easy to write the JavaScript code as to use that Drag-and-Drop GUI, especially if you're already familiar enough with JavaScript to be calling out Math functions.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
#5
June 10th, 2014, 05:10 PM
 david.young Junior Community Member Join Date: Sep 2008 Location: Tucson, AZ Posts: 46
Re: Multiply result of rounding

Thanks for the explanation Dan.

I use the wizard to get some code started, then start editing. Gives me a little head start since I don't get to do more involved scripts all that often.