Adding currency field is returning 'NaN'

samuelscott
Tera Expert

 

Hello I'm trying to add 3 seperate currency fields and have tried several things, however, my client script doesn't seem to work. The alert being "logged" is NaN. Can someone help me find the mistake?

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var arc = g_form.getValue('u_arc_rrc_mrc');
	var otc = g_form.getValue('u_otc');
	var tm = g_form.getValue('u_time_and_materials');
	
	//ARC
	
	var arcNum = 0;
	if (arc!= '') {
		arcNum = parseFloat(arc);
	}
	
	//OTC
	var otcNum = 0;
	if (otc!= '') {
		otcNum = parseFloat(otc);
	}
	
		//T&M
	var tmNum = 0;
	if (tm!= '') {
		tmNum = parseFloat(tm);
	
	var sum = arcNum + otcNum + tmNum;
		
		g_form.setValue('u_total_contract_value_usd',sum);
		
	}
	var str = "ARC Total: " + arcNum + '\n';
	str += "OTC Total: " + otcNum + '\n';
	str += "Time and Materials Total: " + tmNum + '\n';
	alert(str);
}
	

 

 

 

 

 

 

 

2 REPLIES 2

mholmes
Tera Expert

I tried this code in isolation (using nodejs on the command line) and it seems to work as long as the values for arc, otc, and tm are purely numeric.

However, I will get "NaN" for certain values if I include a dollar sign in the string that is passed to parseFloat. For example:

ARC Total: 12.5
OTC Total: NaN
Time and Materials Total: 3

Does g_form.getValue return any characters that would not be understood by parseFloat, such as a dollar sign or other currency symbol?

If so, you can use a regex to remove any troublesome characters from the strings before passing them to parseFloat.

From a bit of Googling, it seems that currency fields are not as well supported on the client side as they are on the server side.

samuelscott
Tera Expert

I appreciate very much your help...On my tests, I onlyinput numbers on the currency fields. 

 

And yes....it does return values that are not understood by parseFloat, for example:

 

find_real_file.png

 

 I've seen examples of a "getCurrencyValue" method but I think it only applies when scripting server side....I'm not sure what is the client side equivalent.