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

Question

Question

Round to 2 decimal points with Forms 10

asked on December 28, 2015

Hello,

I was looking to use the new formulas in Forms 10 but I was unable to find one that would enforce two decimal places for currency calculations. I want $800 to show as 800.00 Is this correct or am I missing something?

I don't mind using javascript, but I like making items as maintainable as possible. Thanks ahead of time.

0 0

Answer

SELECTED ANSWER
replied on December 28, 2015

Hi John,

To add to Alexander's post, if you want two decimals for all currency fields, add the following Javascript:

01$(document).ready(function() {
02 
03  $('.currency').change(function() {
04    $(this).val(formatCurrency($(this).val()));
05  });
06   
07  function formatCurrency(value) {
08    var float = parseFloat(value);
09    return isNaN(float) ? 0 : (Math.round(float*100)/100).toFixed(2);
10  }
11});

This will keep the form maintainable, as you do not have to change the form's fields or their advanced properties.

Let me know if this works for you!

2 0
replied on December 30, 2015

Hi Alexander,

Your solution works suprisingly well.

Thanks,

0 0
replied on January 3, 2017

Has anyone noticed that if they use this code for currency values in a table, it only restricts the first row to two decimals?  All subsequent rows with a currency values are not restricted to two decimals.

0 0

Replies

replied on December 28, 2015

If you want to avoid using JavaScript, would it be sufficient to use a number field instead of a currency field? In Forms 10, the number fields allow you to specify decimal places as well as using the thousands delimiter. It just won't have the currency symbol.

We are looking into making those options available for currency fields as well, but it would be for a future release of Forms.

0 0
replied on December 20, 2016 Show version history

This worked for me with the exception that when used in a table it only works on the first row and NOT on rows that are added as the form is filled out. Is there a tweak I can make to have it work as new rows are added?

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

Sign in to reply to this post.