Home php How to get an integer value of a number in PHP (rounding...

# How to get an integer value of a number in PHP (rounding numbers)? [Duplicate]

Author

Date

Category

There is a number 13.21021
How to withdraw only 13?

``````intval (VAL);
``````

in brackets variable name with the value

For rounding numbers, use the `Float Round function. `– it rounds up with a given accuracy up or down depending on the number. Example:

``````& lt;? php
Echo Round (3.4); // 3.
Echo Round (3.5); // 4
Echo Round (3.6); // 4
Echo Round (3.6, 0); // 4
Echo Round (1.95583, 2); // 1.96
Echo Round (1241757, -3); // 1242000.
Echo Round (5.045, 2); // 5.05
Echo Round (5.055, 2); // 5.06
? & gt;
``````

You can also use the `Float Ceil (Float Value) function `. It rounds the fraction in the nearest whole. Example:

``````& lt;? php
Echo Ceil (4.3); // 5
Echo Ceil (9.999); // ten
Echo Ceil (3.0); // 3.
? & gt;
``````

To round down to a smaller stronger, use the `Float Floor (Float Value) `. In fact, it simply discards the fractional part. Example:

``````& lt;? php
Echo Floor (4.3); // 4
Echo Floor (9.999); // nine
Echo Floor (5.0); // 5
? & gt;
``````

`int intval function) `Allows you to work with rows and translate them to integers.

Examples taken Hence , From here and Hence

Put forced conversion to type:

``````\$ Float = (int) 13.91021;
Echo \$ Float; //13
``````

or

``````\$ float = 13.21021;
Echo (int) \$ Float; //13
``````

or

``````echo intval (13.91021); //13
``````

To learn the fractional part of the number, you can use manipulation type

``````\$ float = 13.21021;
\$ int = (int) \$ Float;
Echo \$ int;
``````

or

``````echo (int) 13.21021;
``````

To display the integer part, so you can use formatted output

``````\$ num = 13.21021;
echo sprintf ( '% d parrots', \$ num);
``````

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.