hello..

i have to do substraction of two php variables which is having datatype varchar.
i am trying like this.

$a=5;
$b=3;
$c=$a-$b;

but for float values

$a=3000.90;
$b=2000;
$c=$a-$b;

out put is $1000.9. ok even i echo $a i am getting 3000.9
how to get two digits after the decimal.

You can use sprintf.

echo sprintf('%.2f', $c);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.