Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tep_round() does not work with negative numbers #406

Open
tgely opened this issue Oct 11, 2016 · 2 comments
Open

tep_round() does not work with negative numbers #406

tgely opened this issue Oct 11, 2016 · 2 comments

Comments

@tgely
Copy link
Contributor

tgely commented Oct 11, 2016

https://github.com/osCommerce/oscommerce2/blob/master/catalog/includes/functions/general.php#L297-L315

There are not interpreted negative numbers in tep_round() function. I dont see where are conflicts with negative currencies so I dont understand the reason.

Here is a quick fix with abs number:

  function tep_round($number, $precision) {
    if ($number < 0) {
      $sign = -1;
    } else {
      $sign = 1;
    }

    $number = abs($number);
    if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) {
      $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1);
      if (substr($number, -1) >= 5) {
        if ($precision > 1) {
          $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1');
        } elseif ($precision == 1) {
          $number = substr($number, 0, -1) + 0.1;
        } else {
          $number = substr($number, 0, -1) + 1;
        }
      } else {
        $number = substr($number, 0, -1);
      }
    }

    return $sign * $number;
  }
@Gergely
Copy link
Member

Gergely commented Nov 28, 2016

@haraldpdl

could be deprecated the tep_round()? There is no php3 compatibility and no negative number functionality at all.

@Gergely
Copy link
Member

Gergely commented Nov 28, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants