You are viewing limited content. For full access, please sign in.

Question

Question

Enter whole dollar amounts only in Currency field on Form (Classic Designer)

asked on October 22, 2024

We have a need to use the currency field along with the $ and , but need to restrict the entry to whole dollars, or if that is not possible, to auto-round to the nearest dollar.  How can this be achieved? 

Our documentation states the following:  Field data can only be restricted for certain field types: text fields and numeric fields (number, integer and long integer). The restrictions that a particular character field will have are determined by regular expressions, a notation used to define a pattern of text. 

Is this need only possible for Currency fields with JavaScripting? 

0 0

Answer

SELECTED ANSWER
replied on October 23, 2024

Uncheck the Use Thousands Delimiter.  When I took that off it rounded correctly.  

0 0

Replies

replied on October 22, 2024

There's probably more than one way to do this, but here's some simple Javascript for the Classic Designer.  Give your field(s) the class name of noDecimal.  When the value of the field is changed, it's rounded off to a whole dollar and reinstated into the field.

$(document).ready(function() {
  
  //When any field with the noDecimal class is changed,
  //round off its value to 0 decimal places and
  //update the field to the new value.
  $('.noDecimal input').change(function() {
    let curVal = parseFloat($(this).val());
    curVal = curVal.toFixed(0);
    $(this).val(curVal);
  });
  
});

 

1 0
replied on October 23, 2024

I greatly appreciate you providing the JS code for me! This is working unless my entry is over 3 digits before the decimal. If 4 or more it returns just the first digit of my entry. 

Examples:

1.55 = 2,   10.45 = 10,   145.98 = 146,  1500.00 = 1

 

0 0
SELECTED ANSWER
replied on October 23, 2024

Uncheck the Use Thousands Delimiter.  When I took that off it rounded correctly.  

0 0
replied on October 23, 2024

As Angela indicated the comma is screwing with the script.  Her suggestion of removing the comma works.  Alternatively, you can tweak the script with a replace statement as follows to remove the comma from the value before it is processed: 

$(document).ready(function() {
  
  //When any field with the noDecimal class is changed,
  //round off its value to 0 decimal places and
  //update the field to the new value.
  $('.noDecimal input').change(function() {
    let curVal = parseFloat($(this).val().replace(/,/g, ''));
    curVal = curVal.toFixed(0);
    $(this).val(curVal);
  });
  
});
1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.