• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Conditional formating on a number

Explorer ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

Need help on some conditional formating.

 

I have a drop down where the user choose one of two contract type.  I've assigned export values to each of the contract type (2 or 4).  

 

Then I need another field to format the number to either 2 decimal places or to 4 decimal places.

 

This is the first time I'm attempting something like and I'm learning all of this as I go.

 

I've looked at some resources but I'm not seeing something similiar to this.

 

I'm thinking I start with 

if contract = this.getField("Contract type").value =4;
then

so the then would be the formatting, but I've not clue how I write that.

 

Then I know I have an else which would be the formatting for 2 decimal places.

 

These figures are monetary, so if I can include that in the formating would be great.

 

Help!

Clueless beginner

TOPICS
How to , JavaScript

Views

187

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

Try this:

var drop = this.getField("Contract type").valueAsString;
if(drop == "2")
event.value = util.printf("%.2f", event.value);
else if(drop == "4")
event.value = util.printf("%.4f", event.value);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

Thank you that worked.  I'm trying to build on it now...

 

So the next field CYP Plus CPI needs to be a formula but formatting based on the that drop down...

 so the result of var CYP is going to be the event.value I think but how to I make it do that.

var CPI = this.getField("CPI").value * this.getField("CY Food").value; // amount of CPI increase
var CYP = Increase + this.getField("CY Food"); // Current Year Plus CPI Increase

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

I finally figured it out.  I'm good to go.  I caught my error in the code above too.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

LATEST

You didn't declare 'Increase' variable, and you are missing '.value' after: this.getField("CY Food")

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines