954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php substraction

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.

muralikalpana
Posting Pro
540 posts since Sep 2009
Reputation Points: 21
Solved Threads: 36
 

You can use sprintf .

echo sprintf('%.2f', $c);
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

thanks for your reply.

muralikalpana
Posting Pro
540 posts since Sep 2009
Reputation Points: 21
Solved Threads: 36
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: