Calculation

Explorer ,
Feb 13, 2021 Feb 13, 2021

Copy link to clipboard

Copied

I'm stuck and not sure how to proceed, I split decimal to calculate but it joins numbers as string instead of calculating them, here is code I use

var c = 0;
for (var i=1; i<=3; i++) {
var a = this.getField("Text"+i).value.split(".");
var c = a[0]+i;}
event.value = c;

TOPICS
JavaScript

Views

90

Likes

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

Adobe Community Professional , Feb 14, 2021 Feb 14, 2021
Try like this:var c = 0; for (var i=1; i<=3; i++) { var a = this.getField("Text"+i).valueAsString.split("."); if(this.getField("Text"+i).value != "") c +=Number(a[0]);} event.value = c;

Likes

Translate

Translate
Adobe Community Professional ,
Feb 13, 2021 Feb 13, 2021

Copy link to clipboard

Copied

What want you calculate?

Likes

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 ,
Feb 13, 2021 Feb 13, 2021

Copy link to clipboard

Copied

I'm trying to split decimal number and then sum whole number separate and decimals separate,

Likes

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 ,
Feb 13, 2021 Feb 13, 2021

Copy link to clipboard

Copied

What happens if you use instead .valueAsString

Likes

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 ,
Feb 13, 2021 Feb 13, 2021

Copy link to clipboard

Copied

It doesn't change anything, I made a mistake above, I thought it show them as string because in first field I had same number as number of fields but actually it doesn't show them as string it's just number of fields and number in last field joined together.

Likes

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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

LATEST

Try like this:

var c = 0;
for (var i=1; i<=3; i++) {
var a = this.getField("Text"+i).valueAsString.split(".");
if(this.getField("Text"+i).value != "")
c +=Number(a[0]);}
event.value = c;

Likes

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