• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

345

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

Community Expert , 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;

Votes

Translate

Translate
Community Expert ,
Feb 13, 2021 Feb 13, 2021

Copy link to clipboard

Copied

What want you calculate?

Votes

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,

Votes

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

Copy link to clipboard

Copied

What happens if you use instead .valueAsString

Votes

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.

Votes

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
Community Expert ,
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;

Votes

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