Skip to main content
Inspiring
December 3, 2023
Answered

Rounding up one of two global number fields

  • December 3, 2023
  • 1 reply
  • 274 views

I have an 'assessment' document that also includes a 'report' template that is generated once the assessment is completed. The report has number fields duplicated from the assessment. I want to round up the numbers on the report up to closest 5, but have the fields on the assessment remain as the number input by the user. Is there any way of doing this? My thought at the moment is that the duplicating fields will need to be removed and number fields with calculation script added. Hope this explanation makes sense and thanks for help.

This topic has been closed for replies.
Correct answer Nesa Nurani

You will have to rename fields, here is an example script that use value from field 1 "Text1" and show rounded value to closest 5 in another field.Script is used as custom calculation script of second field (you could also adapt script and use it as validation script of first field):

var n = Number(this.getField("Text1").valueAsString);
if (!isNaN(n)&& n !== 0)
event.value = Math.round(n / 5) * 5;
else
event.value = "";

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
December 3, 2023

You will have to rename fields, here is an example script that use value from field 1 "Text1" and show rounded value to closest 5 in another field.Script is used as custom calculation script of second field (you could also adapt script and use it as validation script of first field):

var n = Number(this.getField("Text1").valueAsString);
if (!isNaN(n)&& n !== 0)
event.value = Math.round(n / 5) * 5;
else
event.value = "";

Inspiring
December 4, 2023

Thanks Nesa - this is perfect!!