PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Currency Format for Number Field Calculation

  1. mnish
    Member

    How can I format the Number field that's calculating a Product Price and a Quantity? I'm not so concerned with the dollar sign but I would like to have 2 decimal places to show in my Subtotal field when the user changes the Quantity. I have the Rounding set to 2 but if there are trailing zeroes they get cut off.

    Calculation of $5.25 x 2 = 10.5 (Should show as 10.50)

    Posted 12 years ago on Sunday May 13, 2012 | Permalink
  2. mnish
    Member

    Any workarounds for this?

    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  3. kinetic
    Member

    I am also dealing with something similar and would love some input from the support team.

    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  4. Can you post a link to your form?

    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  5. mnish
    Member

    Sorry, it's on a protected page/website. Can I send you the info privately?

    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  6. Sure - rob@rocketgenius.com - just be sure to reference this post in your email.

    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  7. kinetic
    Member

    Rob, i will send you an email with the access info for the form.

    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  8. mnish
    Member

    Thanks, Rob! Just emailed you a link to a sample form that has same issue.

    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  9. Hi Guys,

    Here is a solution to this:

    http://gravitywiz.com/2012/05/24/format-field-as-currency/

    If you'd like to display the currency symbol separately, you'll want to remove it from the formatted number. Replace this line:

    [js]
    $(this).val(gformFormatMoney($(this).val()));

    With this:

    [js]
    $(this).val(gformFormatMoney($(this).val()).replace(\'$\', \'\'));
    Posted 12 years ago on Thursday May 24, 2012 | Permalink
  10. Thanks David!

    The snippet for the functions.php file didn't work for us but the javascript-only code worked perfectly.

    Posted 12 years ago on Friday May 25, 2012 | Permalink
  11. Hi Glenn,

    Glad to hear it. Did you get an error with the PHP version or just didn't work?

    Posted 12 years ago on Friday May 25, 2012 | Permalink
  12. No errors. It just didn't work. Does it have to do with the add_filter? I couldn't find any gform functions called gform_format_money.

    Posted 12 years ago on Friday May 25, 2012 | Permalink
  13. kinetic
    Member

    Same for me. The PHP/Function method did not work, but adding the jquery directly to my header.php file worked like a champ.

    Thanks!

    Posted 12 years ago on Friday June 1, 2012 | Permalink
  14. kinetic
    Member

    It appears that whenever I enable Page Breaks on a form, it nullifies the effect of applying this filter. Anyone else experiencing that?

    Posted 12 years ago on Sunday June 10, 2012 | Permalink
  15. Hi Kinetic (and other's interested in this),

    The functionality has been updated to work a little more globally:

    http://gravitywiz.com/2012/05/24/format-field-as-currency/

    Posted 12 years ago on Tuesday June 12, 2012 | Permalink
  16. EngineMarketing
    Member

    Hi David,

    I was trying to remove the $ sign using your code but it didn't work. It gives an error message "Unexpected $ sign". And there are 2 instances of this line $(this).val(gformFormatMoney($(this).val()));

    which one should be replaced. Though I have tried every combination.

    Your help will be much appreciated.

    Posted 11 years ago on Sunday March 24, 2013 | Permalink
  17. EngineMarketing
    Member

    Hi David,

    I have figured it out. The second instance of the code should be replaces by the following code:

    $(this).val(gformFormatMoney($(this).val()).replace(\'$\', \'\'));

    Your code was not escaped properly and missing one closing first bracket. Just posted this so that it could help others.

    Posted 11 years ago on Sunday March 24, 2013 | Permalink
  18. I'll send this information to David Smith and see if the code needs to be updated or if there is a newer version we can reference or if something else is wrong.

    Posted 11 years ago on Monday March 25, 2013 | Permalink
  19. EngineMarketing
    Member

    Hi David and Chris,

    Another problem now arised. After submission of the form if there are any validation errors with any of the fields other than the currency fields, when the form is shown with the error messages, the dollar sign comes back again. Should I use any other hook?

    I would appreciate your help in this regard.

    Best regards,

    Mahfuz

    Posted 11 years ago on Thursday April 4, 2013 | Permalink
  20. You can use the gform_post_render hook to run your JavaScript after a validation error:
    http://www.gravityhelp.com/documentation/page/Gform_post_render

    Posted 11 years ago on Monday April 8, 2013 | Permalink