Skip to main content
Inspiring
June 21, 2022
Answered

js pdf function to round higher whole number

  • June 21, 2022
  • 1 reply
  • 429 views

Hi
I ask you kindly if anyone can help me build this function
I have 3 fields:
Field 1 = "TYPE OF RATE"
Field 2 = "EURIBOR"
Field 3 = "DURATION IN YEARS"

In field 1 I can write "FIXED RATE" or "VARIABLE RATE".
In field 3 I can write the number of years (10, 12, 15, 18 etc.)
if in field 1 I write "FIXED RATE" I want the text "EURIRS YEARS" + the number indicated in field 3 rounded to the next whole number 5 to appear in field 2.
For example, if I write 12, it must be rounded to 15, if I write 18, it must be rounded to 20 etc

I tried to write this function on validation
if (event.value == "FIXED RATE") {this.getField ("TYPE OF RATE"). value = "FIXED RATE"; this.getField ("EURIBOR"). value = "EURIRS YEARS" + Math.ceil ( this.getField ("DURATION IN YEARS"). value, 5);}

Obviously it doesn't work
It gives me this result
"EURIRS YEARS 0"

Please, can anyone help me?

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

Use this:

var y = Number(this.getField("DURATION IN YEARS").value);
var x = Math.round((y%5)?y-y%5+5:y);
if (event.value == "FIXED RATE") {
this.getField ("TYPE OF RATE").value = "FIXED RATE";
this.getField ("EURIBOR"). value = "EURIRS YEARS " + x;}

1 reply

Nesa Nurani
Nesa NuraniCorrect answer
Adobe Expert
June 21, 2022

Use this:

var y = Number(this.getField("DURATION IN YEARS").value);
var x = Math.round((y%5)?y-y%5+5:y);
if (event.value == "FIXED RATE") {
this.getField ("TYPE OF RATE").value = "FIXED RATE";
this.getField ("EURIBOR"). value = "EURIRS YEARS " + x;}

ENE5CD9Author
Inspiring
June 21, 2022

Thank you very much!!!