Skip to main content
vigneshs53970460
Known Participant
January 29, 2018
Answered

Finding decimal placement in a number field

  • January 29, 2018
  • 5 replies
  • 993 views

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.

This topic has been closed for replies.
Correct answer try67

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

var s = "52.6531"

var indexOfPeriod = s.indexOf(".");

var decimalPart = indexOfPeriod==-1 ? "" : s.substr(indexOfPeriod+1);

5 replies

vigneshs53970460
Known Participant
January 29, 2018

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??

try67
Community Expert
Community Expert
January 29, 2018

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.

vigneshs53970460
Known Participant
January 29, 2018

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

try67
Community Expert
Community Expert
January 29, 2018

Use:

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

vigneshs53970460
Known Participant
January 29, 2018

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.

vigneshs53970460
Known Participant
January 29, 2018

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 29, 2018

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

var s = "52.6531"

var indexOfPeriod = s.indexOf(".");

var decimalPart = indexOfPeriod==-1 ? "" : s.substr(indexOfPeriod+1);

try67
Community Expert
Community Expert
January 29, 2018

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

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

try67
Community Expert
Community Expert
January 29, 2018

You can use the indexOf method, like this:

"52.6531".indexOf(".")

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