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

The value entered does not match the format of the field

New Here ,
Jun 25, 2021 Jun 25, 2021

Copy link to clipboard

Copied

Hi I have had a read few of the forums around this topic but havent found what I am looking for. I am very new to this and am looking for a simple solution.

I have two calculations that I need to do:

1. Weight / height^2 (which I have written as (Weight/(Height/100*Height/100)) as we write our height in cm not m

2. Waist / Hip

I am able to get the calclautions working however I need them to be to 2 decimal places which can be changed under the format tab however the above error message keeps coming up - I know this comes up because you cant divide something by 0. What script can I insert into this to make sure this message doesnt keep coming up?

TOPICS
How to , JavaScript

Views

1.9K

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 , Jun 28, 2021 Jun 28, 2021

You can format "BMI" as number with 2 decimal under format tab, and try this code,put it into 'Custom calculation':

var w = this.getField("Weight");
var h = this.getField("Height");
if(isNaN(w.value) || isNaN(h.value) || w.value == 0 || h.value == 0) event.value = "";
else event.value = w.value/(h.value/100*h.value/100);

Votes

Translate

Translate
Community Expert ,
Jun 25, 2021 Jun 25, 2021

Copy link to clipboard

Copied

Check for 0 in your calculation and set field empty or 0 if it's true, something like this:

if(this.getField("field").value == 0) event.value = "";

else //calculation goes here

of course this is just basic way to do it, it would be helpful if you posted your actual script.

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 ,
Jun 25, 2021 Jun 25, 2021

Copy link to clipboard

Copied

The result can be 0, but 0/0=NaN and 1/0=Infinity, so write instead:

 

if(!isFinite(this.getField("field").value)) event.value = "";
else //calculation goes here

 

 

 

@+

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
New Here ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

This is what I have inserted into both the simplified field notion and custom calculation script but have not had any luck with it calcuating. 

if(!isFinite(this.getField("field").value)) event.value = "";
else //Weight/(Height/100*Height/100)

 

I have tried both of the above scripts. 

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 ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

You can't use the scripts in the simplified field notion.

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 ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

Field name "field" is just example you need to input your field name,also whats are Weight and Height,field names or variables? What are names of two fields you try to calculate and do you use any formats in them?

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
New Here ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

Hi Nesa the field names are 'Height' and 'Weight'. The field name I want the calculation in is 'BMI'.

No formats in height and weight  however I would like to format the BMI to 2 decimal places.

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 ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

You can format "BMI" as number with 2 decimal under format tab, and try this code,put it into 'Custom calculation':

var w = this.getField("Weight");
var h = this.getField("Height");
if(isNaN(w.value) || isNaN(h.value) || w.value == 0 || h.value == 0) event.value = "";
else event.value = w.value/(h.value/100*h.value/100);

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
New Here ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

LATEST

Hi Nesa,

 

This works perfectly and Ive been able to adjust it for my other calulations.

 

Thank you very much!!

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