Skip to content

Commit

Permalink
Merge pull request #65 from frankmullenger/precision-bounds
Browse files Browse the repository at this point in the history
Precision bounds
  • Loading branch information
stevie-mayhew committed Jul 4, 2014
2 parents 762a79b + 45228c2 commit fc9ca70
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
6 changes: 1 addition & 5 deletions code/admin/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ public function FieldHolder($properties = array()) {
public function setValue($val) {
if(!$val) $val = 0.00;
$shopConfig = ShopConfig::current_shop_config();
$precision = 2; //precision should always be two decimals, and only more if specified in ShopConfig
if($shopConfig && $shopConfig->BaseCurrencyPrecision > 2) {
$precision = $shopConfig->BaseCurrencyPrecision;
}
$precision = $shopConfig->BaseCurrencyPrecision;

$this->value = number_format((double)preg_replace('/[^0-9.\-]/', '', $val), $precision);
return $this;
}


public function validate($validator) {
if(!empty ($this->value)
//validate against any number of digits after the decimal place
Expand Down
5 changes: 1 addition & 4 deletions code/form/OrderForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,7 @@ public function process($data, $form) {

try {
$shopConfig = ShopConfig::current_shop_config();
$precision = 2; //precision should always be two decimals, and only more if specified in ShopConfig
if($shopConfig && $shopConfig->BaseCurrencyPrecision > 2) {
$precision = $shopConfig->BaseCurrencyPrecision;
}
$precision = $shopConfig->BaseCurrencyPrecision;

$paymentData = array(
'Amount' => number_format($order->Total()->getAmount(), $precision, '.', ''),
Expand Down

0 comments on commit fc9ca70

Please sign in to comment.