user3878719
user3878719

Reputation: 37

How to remove decimal in PHP?

I am currently echoing a number like this:

<?php echo $enterprise_platinum_price ?>

The problem is that the number normally has a decimal place such as 19.44 or 13.353

I need to display the full number but without the decimal point or any of the numbers behind it. I know that you can round to the full number in PHP but I don't ever want it to round up. If the only way to do this is with rounding, I need it to always round down...

Upvotes: 0

Views: 1632

Answers (1)

Bailey Herbert
Bailey Herbert

Reputation: 410

Use the math floor function to round downward.

$a = floor(1.99); // $a = 1

You can also do it without rounding using number_format. There's many, many more ways, but I think the floor() option is the shortest for you.

$a = number_format(1505.99, 0, '', ''); // $a = 1505

Upvotes: 8

Related Questions