9 Replies Latest reply on Jan 29, 2018 9:33 AM by try67

# Finding decimal placement in a number field

Hi,

I am having a number field ("Number Field") with decimals and I want to know the placement of decimals, it would be dynamic. Sometimes "Number Field" value will be

("52.6531", "526.531", "5265.31") I want to know the exact place of where the decimal starts like (3, 4, 5) answers for the given values.

• ###### 1. Re: Finding decimal placement in a number field

You can use the indexOf method, like this:

"52.6531".indexOf(".")

It returns 2 (the index numbers are zero-based).

• ###### 2. Re: Finding decimal placement in a number field

Thank you much.

After finding "2" is there any option to get the values after decimal to end and paste to another text field.

Example: "6531" I need to get this answer.

• ###### 3. Re: Finding decimal placement in a number field

Sure, there are various ways. Here's one:

```var s = "52.6531"
var indexOfPeriod = s.indexOf(".");
var decimalPart = indexOfPeriod==-1 ? "" : s.substr(indexOfPeriod+1);
```
• ###### 4. Re: Finding decimal placement in a number field

To copy the decimal value to a field add this to the end of the code above:

this.getField("Decimals").value = decimalPart;

• ###### 5. Re: Finding decimal placement in a number field

I used var s = this.getField("Text1").value; instead of "52.6531" because I do not know the exact value and I should get from the "text1" text field. Now, I am getting the error stating "s.indexOf is not function". If you want, I can explain How my output should looks.

• ###### 6. Re: Finding decimal placement in a number field

Sometimes the values of "Text1" field will be 10,000.0000. So, I need to get the exact value.

• ###### 7. Re: Finding decimal placement in a number field

Use:

var s = this.getField("Text1").valueAsString;

• ###### 8. Re: Finding decimal placement in a number field

Apologies, now requirement has been entirely changed.

Now, I am going to keep 3 fields total (Text1, Text2, Text3).

In Text1 values will be only in numbers includes "thousand separators", "decimals" and "negative values" should be replaced as "parentheses".

In Text2 values will be currency type either they can type Dollar or \$. So, that should be consider as text field.

In Text3 values should be "Amount of:" + Text2 and Tex1" (The output should be) for example: Amount of: Dollar 1,000.0000

if the text1 value is "1" and text2 has Euro example: Amount of: Euro 1 if the value is more than thousand we need to include thousand separator.

Value should come as exactly from Text1 including the number of decimals. if "text 1" has "4,556.56412334" or it might come without decimal also "4,556" or 4,556.20 or 4,556.00. So, output should be "Dollar 4,556.56412334" or "4,556" or 4,556.20 or 4,556.00 and If it is negative values we should be replace "-" to parentheses "-4,556.56412334" to (4,556.56412334)

Suppose if they add additional space at the end value from text2 "Dollar " it should replace as "Dollar".

Could you help me to complete this??

• ###### 9. Re: Finding decimal placement in a number field

I suggest you spend some time studying the core JS-syntax.

If you want me to write this code for you feel free to contact me privately (try6767 at gmail.com) and we could discuss it further, including the price.