Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/08/2008, 04:50
gigio_wt
 
Fecha de Ingreso: diciembre-2002
Ubicación: Santiago
Mensajes: 87
Antigüedad: 22 años, 2 meses
Puntos: 0
Pregunta problema usando un numero (string)

Tengo un problema que me ha tenido despierto toda la noche...
recibo un string que es un numero (3 800)
lo recibo en una variable que se llama $total_price
intento forzar la variable como numerica usando el clasico:
$precio = 0+$total_price
sin embargo, me devuelve 0... como decimos en chile: plop!

alguien me puede ayudar o dar una idea sobre esto, probe lo siguiente:
$precio = 1+$total_price
resultado: 1

el tema es que necesito utilizar luego el valor numerico para un par de calculos:
$iva = round(($precio*19)/100);
$neto = $precio - $iva;
por ahora todo me da 0...

si alguien me puede ayudar, gracias...

el codigo completo es:
Cita:
<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

if($empty_cart) { ?>

<div style="margin: 0 auto;">
<?php if(!$vmMinicart) { ?>
<a href="http://virtuemart.net/" target="_blank">
<img src="<?php echo $mm_action_url ?>components/com_virtuemart/shop_image/ps_image/carrovacio.gif" alt="VirtueMart" width="80" border="0" /></a>
<br />
<?php }
echo $VM_LANG->_('PHPSHOP_EMPTY_CART') ?>
</div>
<?php }
else {
// Loop through each row and build the table
foreach( $minicart as $cart ) {

foreach( $cart as $attr => $val ) {
// Using this we make all the variables available in the template
// translated example: $this->set( 'product_name', $product_name );
$this->set( $attr, $val );
}
if(!$vmMinicart) { // Build Minicart
?>
<div style="float: left;">
<?php echo $cart['quantity'] ?>&nbsp;de&nbsp;<a href="<?php echo $cart['url'] ?>"><?php echo $cart['product_name'] ?></a>
</div>
<div style="float: right;">
<?php echo $cart['price'] ?>
</div>
<br style="clear: both;" />
<?php echo $cart['attributes'];
}
}
}
if(!$vmMinicart) { ?>
<hr style="clear: both;" />
<?php } ?>
<div style="float: left;" >
<?php echo $total_products ?>
</div>
<div style="float: right;">
<?php echo $total_price ?>
</div>
<div style="float: right;">
neto->>>
<?php

echo "<span style='color: red;'>$total_price</span><br />";
$precio = 0+$total_price;

echo "<span style='color: red;'>$precio</span><br />";
$iva = round(($precio*19)/100);
$neto = $precio - $iva;

echo "Precio Neto: $".number_format($neto,0,".",".")."<br />Impto. IVA: $".number_format($iva,0,".",".")."<br />Precio Total: $".number_format(($iva+$neto),0,".",".");
?>
</div>
<?php if (!$empty_cart && !$vmMinicart) { ?>
<br/><br style="clear:both" /><div align="center">
<?php echo $show_cart ?>
</div><br/>

<?php }
echo $saved_cart;
?>
__________________
Gigio

Última edición por gigio_wt; 08/08/2008 a las 05:43 Razón: agregar información a la consulta