Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Display values without decimals?

1. ## Display values without decimals?

Hi There,

If I make a calculation for example:

\$a = 1;
\$b = 1.001;

Can I possibly echo \$answer without the .decimals?

If so, please tell me how to do it!

Thanks a lot,

Gil

• I'm pretty sure you should add an (int) in front of the variable you want. Integers do not contain decimal points, so it simply truncates the decimals. For instance:

PHP Code:
``` \$numbertotruncate = (int)\$numbertotruncate;  ```

the second parameter (the 0 ) is the decimel places returned.
and ceil(number) rounds up.

note - you might need to do

• Thanks a lot everyone,

Both methods seem to work. With int I have to add,0. Thanks a lot.

Like this:

<?php

\$a = 1;
\$b = 2.4;

\$d = 1;
\$e = 2.4;

echo "<p>\$a x \$b = \$answer (basic rounding 5+ 4-)";

echo "<p>\$d x \$e = \$answer2 (rounded down)";

echo "<p>\$d x \$e = \$answer3 (rounded up)";

echo "<p>\$d x \$e = \$answer4 (with int rounded down)";

?>

Gil

• or even ....

PHP Code:
``` <? \$a=10;\$b=3.46; echo number_format(\$a * \$b,0);  ?> ```

• Wow! More?

Bye,

• More :
PHP Code:
``` <? \$a = 1.001; \$b = 1; \$result = explode(".",\$a*\$b); echo = result[0]; ?> ```

• Well if we're searching for different ways:
PHP Code:
``` <?php \$a = 1.001; \$b = 1; \$result = \$a * \$b; echo preg_replace('/^(\d+)\.\d+/', '\1', \$result); ?> ```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•