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.

Return value being "trimmed"

  1. I'm adding two number fields together and then passing the total to a hidden field. The problem is if I subtract 10,000 from 100,000 the value returned is 90. However, if I subtract 400,100 from 456,834 it returns the correct value of 56,734.

    Code is as follows:

    //equity valuation
    
        $home_worth = $_POST["input_64"];
        $home_owed  = $_POST["input_65"];
    
        $equity     = $home_worth - $home_owed;
    
        $_POST["input_69"] = $equity;

    I know this has more to do with php than gravity forms but a hand in solving this would be appreciated.

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  2. Assuming the variables are all strings, you might want to try casting input_64 and input_65 as integers before performing math on them.

    How about trying this:

    [php]
    //equity valuation
    
        $home_worth = (int)$_POST["input_64"];
        $home_owed  = (int)$_POST["input_65"];
    
        $equity     = $home_worth - $home_owed;
    
        $_POST["input_69"] = $equity;
    Posted 12 years ago on Wednesday July 25, 2012 | Permalink
  3. Thanks! I gave casting a shot and it didn't work. This one's driving me nutz...any other suggestions?

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink
  4. David Peralty

    Yeah, have a look at the following I did:

    <?php
    $home_worth = intval(str_replace(",","","100,000"));
    $home_owed  = intval(str_replace(",","","10,000"));

    I did a string replace to strip out any commas because that seemed to mess things up. Can you try something similar and let me know if it fixes the issue?

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink
  5. You sir are deserving of an ice cold beverage - that worked...thanks!! You'll also be glad to know that barring any unforeseen issues, that will be my last support request until the next project :)

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink
  6. Good call on stripping out the commas :-)

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink

This topic has been resolved and has been closed to new replies.