• Resolved delfinparis

    (@delfinparis)


    On a currency field, how can I remove the decimal places? I know how to do this on a calculated field, but is there a way to remove the option for a decimal on a currency field?

    Example – I have a currency field where I want someone to enter a non-decimal’ed value. 300,000 vs 300,000.25. Any way to stop that?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    I’m sorry, but that’s not possible without customize the plugin’s code. However, there is an alternative, your currency field is the fieldname6, so, if you insert a “HTML Content” field in the form with the following piece of code as its content you will get this behavior:

    <script>jQuery(document).on('blur', '[id*="fieldname6_"]', function(){this.value = this.value.replace(/\.\d*$/,'');});</script>

    Best regards.

    I don’t understand this (/\.\d*$/, ”), could you explain how this work? I’m trying to replace this 94.976€ with this 94.97€. Thanks in advance!

    Plugin Author codepeople

    (@codepeople)

    Hello @b8engl,

    Your current question is different to the previous one. Now you want only two decimal places, in this case the piece of code to include into a HTML content field would be similar to:

    
    <script>jQuery(document).on('blur', '[id*="fieldname6_"]', function(){
    var v = this.value;
    v = v.replace(/[^\d\.]/g, '');
    v = PREC(v,2);
    this.value = v;
    });</script>
    

    Best regards.

    Thanks for helping me out, but the code does not define two decimal cases. I try in other fields, save before preview but no success. Any idea why?

    Thanks in advance!

    Plugin Author codepeople

    (@codepeople)

    Hello @b8engl,

    I’ve visited your form, and you have not included the code I sent you in the previous ticket. You’re using in the form the code I sent you to remove all decimal places, and it is working fine.

    Best regards.

    I’m using it no on field 22 and i can confirm that is not working. But you could try it your self by adding the 385 value on “Pre?o de Venda – 2 3meses*”, and view the result on field 22 (Valor da Presta??o com Entrada – 22 3meses).

    https://duploclique.pt/simulacao-de-credito-cetelem/

    Thanks in advance!

    Would you consider to add this option on a next update?

    Plugin Author codepeople

    (@codepeople)

    Hello @b8engl,

    If you need the result of the equation with two decimal places, you should use the “PREC” operation:

    PREC(X,Y) rounds the X number with Y decimal places.

    So, your current equation:

    
    (function(){
    if(fieldname54 >= 75) return (fieldname1-fieldname21);
    })()
    

    it should be modified as follows:

    
    (function(){
    if(fieldname54 >= 75) return PREC(fieldname1-fieldname21,2);
    })()
    

    and that’s all.

    WOW! How could you view my code?
    Your solution works great, thanks for all your help and off course, developing this nice and amazing swiss knife.

    Cheers!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to reduce number of decimal places?’ is closed to new replies.