Round up or round down

Explorer ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

I have a field "subtotal"

I want to round up or round down my value from "subtotal" field,

If 50.49 it will be 50.00

If 50.50 it will be 51.00

less than .50 will round down (.10-.49)

greater or equal to .50 will round up

please help me.

I am very new in JavaScript, but this is a great community to learn JavaScript.

 

Views

137

Likes

translate

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

correct answers 1 Correct Answer

Most Valuable Participant , Apr 18, 2021 Apr 18, 2021
OK. Let's say the first quantity field is called Qty1 and the first unit price field is called UnitPrice1. As the custom calculation script of the first total price field enter the following:   var qty = Number(this.getField("Qty1").valueAsString); var price = Number(this.getField("UnitPrice1").valueAsString); event.value = Math.round(qty*price);

Likes

translate

Translate

Translate
Most Valuable Participant ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

Likes

translate

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
Adobe Community Professional ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

[Moderator moved from Creative Cloud Services to Acrobat SDK.]

 

Nancy O'Shea, Adobe Product User & Community Professional
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Likes

translate

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
Most Valuable Participant ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

How are you currently calculating the value of this field?

Likes

translate

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 ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

 

for upload.JPG

 

In 1st row total price will round up $21, and 2nd row total price will be $22.00

19.49 will be 19.00, 19.50 will be 20

 

Likes

translate

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
Most Valuable Participant ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

You did not answer my question...

Likes

translate

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 ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

for upload.JPG

In 1st row total price will round up $21, and 2nd row total price will be $22.00

19.49 will be 19.00, 19.50 will be 20

How I will round up or round down Total Price value?

I am new here.

Likes

translate

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
Most Valuable Participant ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

Let's try it differently. Are you using a script, or the Simple Field Notation option, or the Product option in the Calculate tab?

Likes

translate

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 ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

Using Product Option now.

Likes

translate

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
Most Valuable Participant ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

OK. Let's say the first quantity field is called Qty1 and the first unit price field is called UnitPrice1.

As the custom calculation script of the first total price field enter the following:

 

var qty = Number(this.getField("Qty1").valueAsString);

var price = Number(this.getField("UnitPrice1").valueAsString);

event.value = Math.round(qty*price);

Likes

translate

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 ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

Great, Its work fine,

Thank You Very much.

Likes

translate

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
Most Valuable Participant ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

Be very careful. Money is much harder to work with than many people think, and accountants and others check for errors. Consider: 3 lines, each 4 @ $1.10. So each line is 4.40. You round each line to $4.  The bill must be for $12. 


Seems simple? Now take the grand total. It's 4.40 x 3, which is 13.20 so you round it to $13. So you send someone a bill for which adds up to $12, but charge them $13.  This is likely to lead to bad discussions with accountants, tax authorities and others. 

Likes

translate

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