Reputation: 1398
if($koltukk%4 == 2){
if($koltukk > 1000){
$koltukH = "B";
(int)$koltukR = ($koltukk / 4) + 1;//Doesnt work (int)
}
else{
$koltukH = "E";
(int)$koltukR = ($koltukk / 4) + 1;//Doesnt work (int)
}
}
$koltukR = ($koltukk / 4) + 1;
I want to get the $koltukR variable as an integer but i couldn't do it (int) did not work
Upvotes: 0
Views: 124
Reputation: 6202
One important note here: intval() is NOT round(). intval() is similar to floor().
I think what you really want is round():
Here's the real answer: K.I.S.S.
if($k%4 == 2){
if($k > 1000){
$H = "B"
}
else{
$H = "E";
}
}
$R = round($k / 4) + 1;
Stealing an example from https://www.php.net/intval to illustrate:
echo number_format(8.20*100, 20), "<br />";
echo intval(8.20*100), "<br />";
echo floor(8.20*100), "<br />";
echo round(8.20*100), "<br />";
819.99999999999988631316
819
819
820
Upvotes: 0
Reputation: 686
<?php
if($koltukk%4 == 2)
{
if($koltukk > 1000)
{
$koltukH = "B";
$koltukR = (int)(($koltukk / 4) + 1);
} else{
$koltukH = "E";
$koltukR = (int)(($koltukk / 4) + 1);
}
}
echo $koltukR;
?>
Upvotes: 0
Reputation: 651
PHP has an intval()
method that turns a variable into an integer. Pass in your variable as a parameter.
Upvotes: 0
Reputation: 7005
$koltukR = intval(($koltukk / 4) + 1);
You should use better variable names, move the math out of the if/else since both are the same, and you shouldn't even need to cast this as an int manually.
Upvotes: 0
Reputation: 71384
You need to use the (int)
casting on the other side of the assignment operator:
$koltukR = (int)(($koltukk / 4) + 1);
Or, use intval()
like this:
$kolturR = intval(($koltukk / 4) + 1);
Upvotes: 1