Oliver Balzer: Ausgabe auf 2 Nachkommastellen begrenzen

Hallo zusammen!

Ich betreibe einen 1&1 Onlineshop.
Aufgrund unserer Preisstruktur müssen wir die Einzelpreise mit 4 Nachkommestellen angeben.
Bei den Positionen ist es nun kein Problem, aber in der Gesamtsumme lesen die Kunden dann oft EUR 75,1547 als EUR 75.1547, obwohl das natürlich VÖLLIG utopisch ist. Aber der Kunde ist verschreckt.
Unten habe ich einmal das Script kopiert.
Kann mit irgendjemand sagen, wie ich NUR die Gesamtsumme mit 2 Nachkommastellen anzeigen lassen kann?
VIELEN DANK im Voraus

<?
  $include_basket_table_script= true;

// check if we have US/CA taxes to calculate
  $calUsCaVatRate= (orderinfo_isset("usCaVatRate") || orderinfo_isset("usCaVatRateOnShipping"));

// caluclate subtotals, vat subtotals and total vat
  $sum= 0;
  $total_vat= 0;
  for ($i= 0;$i<$number_of_products;$i++) {
    $basket_subtotal[$i]= item_get_field('price', $basket_items[$i]) * item_get_field('number', $basket_items[$i]);
    $sum+= $basket_subtotal[$i];
    if (!$calUsCaVatRate) {
      // european value added tax
      item_set_field_type('vat', 'double', $basket_items[$i]);
      if ($GROSS_PRICE_MODE)
        $basket_vat[$i]= item_get_field('price', $basket_items[$i]) / (100+item_get_field('vat', $basket_items[$i]))
                         * item_get_field('vat', $basket_items[$i]);
      else
        $basket_vat[$i]= item_get_field('price', $basket_items[$i]) * (item_get_field('vat', $basket_items[$i])/100);
    } else {
      // usa and canada sales tax
      item_set_field_type('vat', 'string', $basket_items[$i]);
      $basket_vat[$i]= (item_get_field('vat', $basket_items[$i]) != "no") ?
        item_get_field('price', $basket_items[$i]) * get_orderinfo_field('usCaVatRate') / 100 : 0;
    }
    $basket_vat[$i]*= item_get_field('number', $basket_items[$i]);
    if ($basket_vat[$i]<0) $basket_vat[$i]= 0;
    if ( !$IGNORE_VAT || $calUsCaVatRate)
      $total_vat+= $basket_vat[$i];
  }

$total_sum= $sum; // amount invoiced
  if (((! $GROSS_PRICE_MODE) && (! $IGNORE_VAT)) || ($calUsCaVatRate))
    $total_sum+= $total_vat;

// make a subtotal of the vat amount just for the basket
  $basket_vat_amount= $total_vat;
  if ($CALCULATE_DELIVERY_AND_PAYMENT)  { // calculate shipping fee
    // read in data of delivery method
    if (! isset($shipping_fee)) {
      $i= 0;
      while (is_array($available_delivery_methods[$i])) {
        if ($available_delivery_methods[$i][name] == get_delivery_method()) {
          $thresholds= $available_delivery_methods[$i][threshold_values];
          $minimum_shipping_fee=     $available_delivery_methods[$i][minimum_fee];
          $vat_rate_on_shipping_fee= $available_delivery_methods[$i][vat_rate];
          $shipping_rule= $available_delivery_methods[$i][rule];
          break;
        }
        $i++;
      }
      $shipping_fee= false;
      if (is_array($thresholds)) {
        $i= 0;
        while ($thresholds[$i]) {
          $current_threshold= $thresholds[$i][threshold];
          if ($total_sum <= $current_threshold) {
            $shipping_fee= $thresholds[$i][fee];
            break;
          }
          $i++;
        }
      }
      if ($shipping_fee === false)
        $shipping_fee= $minimum_shipping_fee;
      if ((isset($vat_rate_on_shipping_fee)) && ($vat_rate_on_shipping_fee!=""))
        $VAT_ON_SHIPPING_FEE= $vat_rate_on_shipping_fee;
    }

// get and excecute the rule of the payment method
    $payment_index= getPaymentIndex(get_payment_method());
    $current_payment_method= &$available_payment_methods[$payment_index];

if ($payment_index!=-1) {
      if (trim($current_payment_method[Rule]) != "") {
        eval($current_payment_method[Rule]);
      }
      if ($current_payment_method[function_calculate_basket]!="") {
        $funcname= $current_payment_method[function_calculate_basket];
        if (function_exists($funcname))
          $funcname();
      }
    }

// execute the shipping rule
    if (trim($shipping_rule) != "") {
      eval($shipping_rule);
    }

// execute the common rule for all payment methods
    if (trim($RULE_PAYMENT_METHOD) != "") {
      eval($RULE_PAYMENT_METHOD);
    }

// calculate vat on shipping fee
    $vat_amount_on_shipping_fee= 0;
    if (!$calUsCaVatRate) {
      // european value added tax
      if ($GROSS_PRICE_MODE)
        $vat_amount_on_shipping_fee= $shipping_fee/(100+$VAT_ON_SHIPPING_FEE)*$VAT_ON_SHIPPING_FEE;
      else
        $vat_amount_on_shipping_fee= $shipping_fee*($VAT_ON_SHIPPING_FEE/100);
      if ($vat_amount_on_shipping_fee<0) $vat_amount_on_shipping_fee= 0;
    } else {
      // usa and canada sales tax
      if (get_orderinfo_field("usCaVatRateOnShipping") != "")
        $vat_amount_on_shipping_fee= $shipping_fee * get_orderinfo_field("usCaVatRateOnShipping");
    }
    $total_vat+= $vat_amount_on_shipping_fee;
    $total_sum+= $shipping_fee;
    if (((! $GROSS_PRICE_MODE) && (! $IGNORE_VAT)) || ($calUsCaVatRate))
      $total_sum+= $vat_amount_on_shipping_fee;
  }

// calculate vat for additional costs
  $vat_amout_per_rate= array(); // calculate vat amounts for each vat rate
  $total_sum+= $additional_costs;

if ( !$IGNORE_VAT || $calUsCaVatRate) {
    for($i= 0; $basket_items[$i]; $i++) {
      $vat_amout_per_rate[(string)item_get_field('vat', $basket_items[$i])]+= $basket_vat[$i];
      $amount_per_rate[(string)item_get_field('vat', $basket_items[$i])]+= item_get_field('price', $basket_items[$i]) * item_get_field('number', $basket_items[$i]);
    }
    if ($additional_costs != 0) {
      // here we reduce or increase the vat amounts
      foreach ($vat_amout_per_rate as $rate => $amount) {
        $vat_rate_factor= $amount_per_rate[$rate]/$sum;
        $vat_rate_factor= ($vat_rate_factor === false) ? 1 : $vat_rate_factor;
        if ($GROSS_PRICE_MODE) {
          $vat_amout_per_rate[$rate]+= $additional_costs * $vat_rate_factor / (100 + $rate) * $rate;
        } else {
          $vat_amout_per_rate[$rate]+= $additional_costs * $vat_rate_factor / 100 * $rate;
        }
      }
    }
    if ($CALCULATE_DELIVERY_AND_PAYMENT)
      if (!$calUsCaVatRate) {
        $vat_amout_per_rate[$VAT_ON_SHIPPING_FEE]+= $vat_amount_on_shipping_fee;
    } else {
      $vat_amout_per_rate['yes']+= $vat_amount_on_shipping_fee;
    }
    unset($vat_amout_per_rate['no']);

// calculate new total vat
    $total_vat= 0;
    foreach ($vat_amout_per_rate as $rate => $amount) {
      $total_vat+= $amount;
    }
  }

// if we have net prices we tampered the vat amounts, so we have to
  // recalculate the total sum (which contains the single vat amounts)
  if (!$GROSS_PRICE_MODE && !$IGNORE_VAT) {
    $total_sum= $sum;
    foreach ($vat_amout_per_rate as $rate => $amount) {
      $total_sum+= $amount;
    }
    if ($CALCULATE_DELIVERY_AND_PAYMENT)
      $total_sum+= $shipping_fee;
    $total_sum+= $additional_costs;
  }

//$total_sum = round($total_sum, 2);

?>

  1. @@Oliver Balzer:

    Kann mit irgendjemand sagen, wie ich NUR die Gesamtsumme mit 2 Nachkommastellen anzeigen lassen kann?

    Mit printf().

    Warum postest du den gesamten irrelevanten Code?

    Was hat das mit HTML/XHTML zu tun?

    Live long and prosper,
    Gunnar

    --
    Erwebsregel 208: Manchmal ist das einzige, was gefährlicher als eine Frage ist, eine Antwort.
    1. Hi,

      Mit printf().

      ich denke number_format ist hier eher geeignet: http://de.php.net/manual/de/function.number-format.php

      Warum postest du den gesamten irrelevanten Code?

      Ansonsten stimme ich Dir selbstverständlich zu ;-)

      Gruesse, Joachim

      --
      Am Ende wird alles gut.