Reputation: 337
Lets say the variable $number holds a decimal like 16.66677666777
How would I make it echo $number and just say 16 rather than 16.66677666777?
Upvotes: 0
Views: 119
Reputation: 3450
Just use inval function
http://php.net/manual/en/function.intval.php
$number = 16.66677666777;
echo intval($number); //16
Upvotes: 1
Reputation: 15938
You could cast it to an integer:
echo (int) $number;
or using intval
:
echo intval($number);
Or you could use the mathematic function floor
to round the number down.
echo floor($number);
This function keep the variable type float.
Here you'll find a small example: http://codepad.org/4um8gJSi
Upvotes: 1
Reputation: 14523
Just use intval function
$number = 16.66677666777;
$number = intval($number);
Upvotes: 1
Reputation: 68446
This will suffice.
<?php
$number=16.66677666777;
echo (int)$number; //16
Upvotes: 1