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.

Accesing Price as Numeric Value

  1. Hi,

    Apologies if this is an obvious question but can't find anything in the documentation. I have a pricing field - single product. When I display the price it displays with the currency symbol intact - e.g. $1.50. How do I access the numeric version of that - i.e. 1.5?

    Many Thanks.

    Michael

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  2. David Peralty

    What do you mean by "access". What are you attempting to do?

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  3. Hi David,

    Thanks for getting back to us. I just want to perform a calculation on the value so I need to strip all of the currency formatting from it and deal with it as a number. Basically if price is less than 10 do something, else do something different.

    Thanks.

    Michael

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  4. David Peralty

    Can you link to your form as it exists currently? You should be able to perform calculations on the price without doing anything special.

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  5. Hi David,

    It's on a local server I'm afraid. Can you tell me how I would perform a calculation - e.g. detect if the price is less than 10?

    Thanks.

    Michael

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  6. David Peralty

    What are the two things you want to do? If the price is higher or lower, what are you hoping to have happen?

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  7. Hi David,

    I'm just using that as an example to see if there is a simple way of getting the price in numeric format.

    The actual script I'm working on is for integration with a third party payment system. I'm using gform_validation to send the payment information to a payment processor. I have it working fine, but currently have to hard code the amount as it won't work with a non-numeric figure.

    Thanks.

    Michael

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  8. David Peralty

    I'm pretty sure the value of that field is a number and not a string. Have you tried to access it yet?

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  9. Hi David,

    I have a form with a fixed price product (it's a registration fee). In the admin area I add it as a Product of type Single Product. I disable the Quantity and enter the Price as 0.50. When I click outside of the Price box the price is automatically reformatted to include the currency - i.e. 0,50€.

    When I run the validation script I use the following code.

    $form = $validation_result["form"];
    foreach($form['fields'] as &$field){
    var_dump($field);
    }

    In the output for this field the only place I can find the figure 0.50 is

    ["basePrice"]=>
    string(8) "0,50 €"

    But this is as a string, not a number.

    Best Regards.

    Michael

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  10. Just following up on this. I found a post here -
    http://www.gravityhelp.com/documentation/page/Gform_currencies

    with details of how to re-format the currency string. I've removed the euro symbol and now I can use as a number. Not the most elegant solution but it's fine for my needs.

    Posted 11 years ago on Saturday May 4, 2013 | Permalink