Copy link to clipboard
Copied
Hi,
Could someone help me on how to modify this code so that the result would have 2 decimal places. tried changing the last part to: event.value="Php "+util.printf("%,0.2f", event.value), but didn't work.
Here's the script I used in custom format.
var x = event.value;
var n = x.toString().split(".");
n[0] = n[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
if(event.value == 0) event.value = "";
else event.value = "Php "+ n.join(".");
Hope someone could help. Thank you.
Hello,
Already found the solution which worked for me. I removed the other code, which maybe the reason for util.printf not working.
Here's the code:
if(event.value == 0) event.value = "";
else event.value="Php "+util.printf("%,0.2f", event.value);
Thank you.
Copy link to clipboard
Copied
How exactly is the util.printf code not working? There is nothing wrong with it.
did you look in the console window for reported errors?
The other code that doe the split does not round. So it is incorrect for your stated purpose.
Copy link to clipboard
Copied
Hello,
Already found the solution which worked for me. I removed the other code, which maybe the reason for util.printf not working.
Here's the code:
if(event.value == 0) event.value = "";
else event.value="Php "+util.printf("%,0.2f", event.value);
Thank you.
Copy link to clipboard
Copied
Well of course, you can't have to scripts competing for the same task.
That's an important programming lesson.
Copy link to clipboard
Copied
How can I get this formual to round to only 2 decimals? The formula works perfectly for what I need except I am getting this as my result: 5.208333333333334 and I want it to read 5.21
var v1 = Number(this.getField("Current Salary").valueAsString);
var v2 = Number(this.getField("New Salary").valueAsString);
if (v2==0) event.value = "";
else event.value = (((v2-v1)/v1)*100.00);
Copy link to clipboard
Copied
Never mind - I was actaully able to figure it out 🙂
var v1 = Number(this.getField("Current Salary").valueAsString);
var v2 = Number(this.getField("New Salary").valueAsString);
if (v2==0) event.value = "";
else event.value = (((v2-v1)/v1)*100.00); event.value=util.printf("%,0.2f", event.value);