Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 90168

Re: How to compare two currency form fields and display a message if the fields do not equal?

$
0
0

Since the field values that you want to compare are the results of calculations, you should not normally compare their string values, but rather their numeric values when rounded appropriately (and perhaps then converted to a string). For example, if you have two values that display as 3.14, one could be 3.1400000001 and the other could be 3.13999999999991234. When you get the field values as strings and compare them, they won't be equal though they appear to be. Even some values that are numerically identical won't be equal when compared as strings ("0.0" != "0.00") So the code could be changed to:

 

// Get the two field values, rounded to two decimals

var v1 = util.printf("%.2f", getField("Total_1").value);

var v2 = util.printf("%.2f", getField("Total_2").value);

 

// Hide/Show the error message

event.value = (v1 === v2 || (+v1 === 0 && +v2 === 0)) ? "" : "Error message here.";


Viewing all articles
Browse latest Browse all 90168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>