3

Tengo varios vectores como arrays y de estos vectores solo a 1 deseo ponerle el estado con decimales y separador de miles.

Cómo hacerlo sin que me ponga el formato a las demás columnas?

$Vec_PARTEVBLE[20][0]="f_creacion";
$Vec_PARTEVBLE[20][1]="";
$Vec_PARTEVBLE[20][2]="Fecha Creación";
$Vec_PARTEVBLE[20][3]="0";

$Vec_PARTEVBLE[21][0]="d_referencia_prov";
$Vec_PARTEVBLE[21][1]="";
$Vec_PARTEVBLE[21][2]="Referencia Prov.";
$Vec_PARTEVBLE[21][3]="0";

$Vec_PARTEVBLE[22][0]="pr_venta_actual";
$Vec_PARTEVBLE[22][1]="";
$Vec_PARTEVBLE[22][2]="Pr. Venta Actual";
$Vec_PARTEVBLE[22][3]="0";

Al único que quiero ponerle el formato es a pr_Venta_Actual

En mi formulario tengo lo siguiente:

if ($parte_vble > 0) {
    for ($k = 0; $k < $parte_vble; $k++) {
        if ($mat_datos[0][$i] == $Vec_PARTEVBLE[$k][0]) {
            if ($Vec_PARTEVBLE[$k][1] != "") {
                $inc_i = 2;
                $d_campo = $Vec_PARTEVBLE[$k][1];
            } else {
                $inc_i = 1;
            }
            $k = $parte_vble;
            $sw_total = 0;
        }
    }
}

Lo que hice fue ponerlo de esta manera:

if ($parte_vble > 0) {
    for ($k = 0; $k < $parte_vble; $k++) {
        if ($mat_datos[0][$i] == $Vec_PARTEVBLE[$k][0]) {
            if ($Vec_PARTEVBLE[$k][1] != "") {
                $inc_i = 2;
                $d_campo = $Vec_PARTEVBLE[$k][1];
            } else {
                $inc_i = 1;
            }
            $k = $parte_vble;

            if ($d_campo = $Vec_PARTEVBLE[$k][25]) {
                $sw_total = 1;
            } else {
                $sw_total = 0;
            }

        }
    }
}


if ($inc_i == 1) {
    if ($sw_total == 1) {
        //echo "*-".$i.'-'.$mat_datos[$j][$i];
        //$dato = pimus_format($mat_datos[$j][$i],2,0);
        //var_dump($mat_datos);
        //echo "<br>decimal:<br>".$valorDecimal;
        $dato = number_format($mat_datos[$j][$i], $valorDecimal, $separadorDecimales, $separadorMiles);
    } else {
        $dato = $mat_datos[$j][$i];
    }
}
2
  • y porque no compruebas cuando vayas a imprimir el datos si el elemento $Vec_PARTEVBLE[ X ][0] el igual a "pr_venta_actual"? si es igual le aplicas el number_format y si no lo es lo muestras como sea
    – Spidvmp
    el 28 abr. 2016 a las 10:02
  • Genial, muchas. el 30 abr. 2016 a las 14:04

1 respuesta 1

1

Se puede recorrer el array fila por fila. Cuando se encuentra el valor en $a[0], se reemplaza el valor de $a[3].

Para formatear el número con 2 decimales y separador de miles se usa number_format($valor, 2).

foreach ($Vec_PARTEVBLE as &$fila) {
    if ($fila[0] == 'pr_venta_actual') {
        $fila[3] = number_format($fila[3], 2);
    }
}

Demo en ideone.com

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.