In php I am doing multiplication. Here my code is like this
$a = 25.20
$multiplication = (int)$a * 2;
echo $multiplication;
here its showing 50
So how can I get the actual values here?
You are using int
datatype as a result.
Use:
$a = 25.20;
$multiplication = (float)$a * 2;
echo $multiplication;
In php you don't need to do type casting because php do it for you.But if you want to you can. In your code you are using int
as datatype but you want decimal values as datatype for that you have to use float
.
Simplest way to do it:
$a = 25.20;
$multiplication = $a * 2;
echo $multiplication;
You will get same result.
you should cast float
instead of int, for you to return decimal places
$a = 25.20;
$multiplication = (float)$a * 2;
echo $multiplication;