0
<?php
$result = array_filter($_POST);    
if(!empty($result)){
echo ((max($result)+min($result))/2)*1.2 ."|".((max($result)+min($result))/2)*1.3;
}
?>

hi all..how to set min and max result to 2 decimals places for the code above? actually the result will appears in input type text after the process complete

  • 1
    Does this answer your question? [Show a number to two decimal places](https://stackoverflow.com/questions/4483540/show-a-number-to-two-decimal-places) – Umer Abbas Apr 12 '20 at 10:24

1 Answers1

2

Use number_format function in PHP.

number_format ( float $number [, int $decimals = 0 ] ) : string
For more information see here

$yourNumber = 1235.343;

echo number_format ($yourNumber, 2);

// Will output 1,235.34 (with two decimals, specified in number_format as second paramter.

Edit: Max / Min functions return mixed value. Make sure its float and then pass it to number_format. It will returns you the string.

davidev
  • 7,694
  • 5
  • 21
  • 56