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

Question

Question

CODE: Format Fields to specific number of characters. And format Currency/Calculations to be only 2 decimals

asked on February 24, 2015

So I need to specify that a number field be  ONLY 11 characters long (it is an account number)

 

And I need to format my Calculations for Amount and Total, to only have / hold 2 decimal places - setting them as currency isn't doing it.

 

Here is my code for the calculations that I got from a Help File....

 

$(document).ready(function () {
$('.cf-table-block').on('blur', 'input', sumtotal);
if ($('.subtotal').length > 0) {
$('.cf-table-block').on('blur', 'input', rowtotal);
}
function sumtotal() {
var sum = 0;
$('td.sum').each(function () {
var s = 0;
$(this).find('input').each(function () {
s += parseNumber($(this).val());
})
$(this).find('.subtotal input').val(s);
sum += s;
});
$('.total input').val(sum);
}
function rowtotal() {
var sum = 0;
$('.cf-table-block tbody tr').each(function () {
var s = 0;
$(this).find('.sum input').each(function () {
s += parseNumber($(this).val());
})
$(this).find('.subtotal input').val(s);
sum += s;
});
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});

0 0

Answer

SELECTED ANSWER
replied on February 24, 2015 Show version history

For configuring a field to only allow an 11 digit numerical input, use a single line field and in the advanced options, use a regular expression like

\d{11}

 

As for performing calculations and limiting to two decimal places, please try the code in this previous thread. Use the .toFixed() method to limit the number of decimal places to two.

0 0

Replies

replied on February 25, 2015

Thanks.  I think I have it working.  I suppose it can't validate during entry and actually not accept anything more than 2 decimals, and can only validate after the user has moved to the next field....then it goes RED to demonstrate improper format...

 

Another question - How can I generate a random number of say 6 digits that won't be repeated ?  We need to assign a deposit number or bill number for tracking purposes that won't be repeated.  Maybe a concatenation of the date and a random number.... is there something like %Date Rand() that could make this work ?

0 0
replied on February 25, 2015

For something like the deposit number I like to use a database to start out with a number.  Have forms grab the number in the database.  When the form is done, I then send it to workflow to look at the number in the database and add 1 to it so I can get a sequential numbering that will not repeat.  It is not random that way, but it does ensure that it wont repeat.

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

Sign in to reply to this post.