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

Question

Question

Apply comma and two decimal places script

asked on January 26, 2016 Show version history

I have tried to follow the scripts on other questions but they don't seem to be working for me. I applied the css class "comma" to my fields that need to have that style. I am not sure if this is for Forms Version 10. Please see below. I just need to comma separator and to round to 2 decimal place. I found  

$(document).ready(function() {

  $('.comma').change(function() {
    $(this).val(formatCurrency($(this).val()));
  });
  
  function formatCurrency(value) {
    var float = parseFloat(value);
    return isNaN(float) ? 0 : (Math.round(float*100)/100).toFixed(2);
  }
});

0 0

Answer

SELECTED ANSWER
replied on January 27, 2016

Fianlly figured this out. Thanks for your help

1 0

Replies

replied on January 26, 2016 Show version history

Try this java script for your form:

Just make sure you the change word "changemetoyourcurrencyclass" to the field class name:

 

$(document).ready(function () {
  
  $('.changemetoyourcurrencyclass input').attr("pattern", '^(\\d+|\\d{1,3}(,\\d{3})*)(\\.\\d{2})?$');
  
  $('.changemetoyourcurrencyclass input').on("change", function () {
    $(this).val($(this).val().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
  });
  
});

 

1 0
replied on January 26, 2016

I saw this script and I tried to change "changemetoyourcurrencyclass" with comma. Only issue I have is when I try to type $1000.00 I get an error.

0 0
replied on January 26, 2016

See below. this is the problem. It's not holding this style in the subtotal box. I applied that css style. I want it to automatically change this to fit. 

0 0
replied on January 26, 2016

It not a table. Just a normal field.

0 0
SELECTED ANSWER
replied on January 27, 2016

Fianlly figured this out. Thanks for your help

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.