Format with decimals

4

I have several vectors as arrays and from these vectors only 1 wish to put the state with decimals and thousands separator.

How to do it without having to format the other columns?

$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";

The only one I want to put the format to is pr_Venta_Actual

In my form I have the following:

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;
        }
    }
}

What I did was put it this way:

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];
    }
}
    
asked by Norbey Martinez 27.04.2016 в 16:32
source

1 answer

2

The array can be traced row by row. When the value is found in $a[0] , the value of $a[3] is replaced.

To format the number with 2 decimals and thousands separator use number_format($valor, 2) .

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

Demo on ideone.com

    
answered by 23.08.2016 в 06:30