Q:

how to give a limit to floating point or define data type to the variable in php

I have a project, in which I have to display difference of two variable with only two digits after point.
following is my php code..
  <?php

    $a=13.987647003;
    $b=10.2000003;
    $c=$a-$b;
    echo $c;
 ?>

output:3.787646703 
I want output:3.78
How can I define this limit? thank you for helping..

A:

Use number_format(), Take a look on the example and apply according to need
$a=13.987647003;
echo number_format($a, 2, ".", "");
// 13.99

Alternate:
$a= 13.987647003;
echo number_format(floor($a*100)/100, 2, ".", "");
// 13.98

http://codepad.org/JkPShrR1

