ster ster - 3 months ago 7
PHP Question

PHP - change number format

I have this code:

<?php
if(isset($_POST['get_luna_inceput'])){
$ret =[];
$sch_luna_inceput = $_POST['get_luna_inceput'];
$sql = "SELECT
...";
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$ret[] =[$row['JUDET'], floatval($row['TOTAL'])];
}
}
}
echo json_encode($ret) ;
?>


My code sql returns values for
$row['TOTAL']
in number format (1523,45). How can I change in format (1.523,45)? I tried this:
$ret[] =[$row['JUDET'], number_format(floatval($row['TOTAL']),2,",",".")]
and not work.Thank you!

Answer
$num = 1523.45;
echo number_format ( $num, 2, ",", "." );

executes 1.523,45

in your case it will be

$ret[] = [ $row['JUDET'], number_format( $row['TOTAL']), 2, ",", ".") ];

Hope it helped