# Thread: How do i get the decimal part of a division?

1. ## How do i get the decimal part of a division?

Hello,

How does on get in PHP the decimal of a division?
That is say you divide 110/30 the result is 3.667

How does one get the 0.667 part of the above number?

Regards,

2. PHP Code:
``` \$x = 110 / 30; \$decimal_part = \$x - floor(\$x);  ```
Although, you may want to take a look at the modulo operator:
PHP Code:
``` \$x = 110 % 30;  ```

3. Another example, casting to an integer instead of calling the float function.
PHP Code:
``` \$result = 110 / 30;\$decimal = \$result - (int) \$result;  ```

4. ThanX. This works fine.
Have a great day

Originally Posted by kyberfabrikken
PHP Code:
``` \$x = 110 / 30; \$decimal_part = \$x - floor(\$x);  ```
Although, you may want to take a look at the modulo operator:
PHP Code:
``` \$x = 110 % 30;  ```

#### Posting Permissions

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