Skip to main content
Inspiring
June 20, 2023
Answered

Change decimal to percentage format

  • June 20, 2023
  • 2 replies
  • 1045 views

My question focuses on Acrobat text fields with the number format and the percentage format, specifically, how do you convert a number to a value that will be accepted in a field with the "Percentage" format so that you don't get this: "The value entered does not match the format of the field"
The dividend and divisor values are from Number formatted fields (1) and (2):
(1) var moBalance = getField("num.PrincipalBalance");
(2) var salePrice = +getField("num.SS.Charge.SalePrice").value;
The recipient field (3) for the quotient is "num.LTV" which is formatted as a Percentage.
         var moLTV = getField("num.LTV");
               moLTV.value = (moBalance.value/salePrice);
This throws the error "The value entered does not match the format of the field"
I prefer to leave "num.LTV" as a percentage format, not to have to change it to Number format.

This topic has been closed for replies.
Correct answer ODuinn

Thank you, and I understand why you suggest this. My script above is part of a larger script that is conditioned on salePrice having a value, and therefore that is not the source of the error. I have just learned that if I multiply the quotient of  moBalance.value/salePrice by 100 

             like this: moLTV.value = (moBalance.value/salePrice)*100

Say the quotient of moBalance.value/salePrice is .94321, so multiplying it by 100 changes it to 94.321, and then the field with the percentage format accepts the value.

I am curious about your use of .valueAsString with numbers. I have not seen .valueAsString used with numbers. What is the reason that you use .valueAsString instead of .value?

2 replies

Nesa Nurani
Community Expert
Community Expert
June 20, 2023

You get error because calculation try to divide by zero, check that 'salePrice' is not zero.

To get decimal divide result with 100.

var moBalance = Number(this.getField("num.PrincipalBalance").valueAsString);
var salePrice = Number(this.getField("num.SS.Charge.SalePrice").valueAsString);
var moLTV = this.getField("num.LTV");
if(salePrice !== 0)
moLTV.value = (moBalance/salePrice)/100;
else
moLTV.value = 0;
ODuinnAuthorCorrect answer
Inspiring
June 20, 2023

Thank you, and I understand why you suggest this. My script above is part of a larger script that is conditioned on salePrice having a value, and therefore that is not the source of the error. I have just learned that if I multiply the quotient of  moBalance.value/salePrice by 100 

             like this: moLTV.value = (moBalance.value/salePrice)*100

Say the quotient of moBalance.value/salePrice is .94321, so multiplying it by 100 changes it to 94.321, and then the field with the percentage format accepts the value.

I am curious about your use of .valueAsString with numbers. I have not seen .valueAsString used with numbers. What is the reason that you use .valueAsString instead of .value?

Bernd Alheit
Community Expert
Community Expert
June 20, 2023

You will get the message when salePrice is zero.