How to add more decimal places in Currency field

I posted this one earlier and got an answer I thought solved it, but it created another issue.

The issue is I’m trying to expand the number of decimals in some Currency fields, without affecting all other currency fields.

For background, I need expanded decimals because users enter in price per share of stock. And sometimes per share price is less than a cent. So they need to be able to enter something like $0.0059383.

I then have a Number field where they enter the number of shares, like 5,000. And then there’s a calculation field that multiplies them together and displays as a currency rounded 2 decimal places like $29.69.

I tried the below snippet that allowed 10 decimal places, but it made EVERY currency field 10 decimal places. How can I allow for 10 decimal places in some areas, but rounded to 2 in others?

add_filter( ‘gform_currencies’, function( $currencies ) {
GFCommon::log_debug( METHOD . ‘(): running.’ );
// Remove space after the currency symbol.
$currencies[‘GBP’][‘symbol_padding’] = ‘’;
return $currencies;
} );

One idea I had was maybe change the Currency field into a Number field and then have a snippet that adds a dollar sign before the field. This way it’s able to have unlimited decimal places, and displays the dollar sign to the user so they don’t know the difference. But I don’t know what that snippet code would be.

The snippet you pasted is only to remove the currency symbol, it doesn’t include any line to change the number of decimals for the currency. You would need to use this:

add_filter( 'gform_currencies', function( $currencies ) {
    GFCommon::log_debug( __METHOD__ . '(): running.' );
    $currencies['GBP']['decimals'] = 10;
    return $currencies;
} );

That will apply to any field using the currency format and GBP as currency.

I think I pasted the wrong snippet. Is it possible to isolate the change of decimal places snipper for some fields and not others?

The currency setting is global, so it’s applies to all fields using the currency format. Doing it per field is not supported.

Understood. In that case, I’m wondering if there’s workaround…Is it possible to add a “$” in front of a specific Number field, whether as a snippet or CSS?

How about some CSS to add a background image of a dollar sign inside the input? First, I added a “Custom CSS Class name” of add_currency to the number field. Then I used this CSS:

body .gform_wrapper .add_currency input {
  background-image: url('');
  background-repeat: no-repeat;
  padding-left: 32px!important;

Which made the number input look like this: firefox xR6xmFO7my.mp4 - Droplr

You would need to download or create an image of a dollar sign in the correct size for your input, then store that on your server or somewhere accessible. (The image on my server will be deleted at some point, so don’t link to that.) You can adjust the padding based on the size of the image and the size of your input to whatever works for you. If you have any other questions, please let us know.

Thanks Chris. I appreciate your help. I just found a plugin that solved my issue. It’s from GravityWP. They have a feature where I can add a symbol before or after a number. So it was actually a pretty simple fix :slight_smile:

1 Like

Thank you for sharing that solution here!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.