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

# Rounding down a calculation

New Here ,
Apr 25, 2024 Apr 25, 2024

Copied

Hello Group,

I am working on a converting a PDF to a fillable form. There are mulptiple equations that I have solved so far but I am stuck on this one. The calculation that I am using is figuring out how many trees per acre is needed. I have the field formatted to only show the integer, but in another calculation using the sum below, it adds the decimals to the end changing the final number Since I can not plant a fraction of a tree, I want to drop everything past the decimal.

Thanks in advance, y'all are awesome!

// Custom calculate script
// Get the field values, as numbers
var numerator = +getField("Spacing1").value;
var denominator = +getField("Spacing2").value;
// Calculate and set this field value
if (denominator !== 0) {event.value = 43560/(numerator * denominator);} else {event.value = "";}

TOPICS
How to , JavaScript , PDF forms

Views

87

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 Expert , Apr 25, 2024 Apr 25, 2024

To round down, you can use Math.floor(),

also, since you multiply numerator and denominator, you need to check that both are not 0.

Try this:

``````var numerator = Number(this.getField("Spacing1").valueAsString);
var denominator = Number(this.getField("Spacing2").valueAsString);

if (denominator !== 0 && numerator !== 0) {
event.value = Math.floor(43560/(numerator * denominator));}
else {
event.value = "";}``````

Community Expert ,
Apr 25, 2024 Apr 25, 2024

Copied

LATEST

To round down, you can use Math.floor(),

also, since you multiply numerator and denominator, you need to check that both are not 0.

Try this:

``````var numerator = Number(this.getField("Spacing1").valueAsString);
var denominator = Number(this.getField("Spacing2").valueAsString);

if (denominator !== 0 && numerator !== 0) {
event.value = Math.floor(43560/(numerator * denominator));}
else {
event.value = "";}``````