Here is a simple example:

Discuss hot database and enhance operational efficiency together.
Post Reply
rifat28dddd
Posts: 668
Joined: Fri Dec 27, 2024 12:22 pm

Here is a simple example:

Post by rifat28dddd »

Here is a small example source code that illustrates the use of the round() function in Python:

num = round ( 3.5 )
print ( num )
Result:

alex@alex-pc:~$ /bin/python3 /home/alex/test.py
4
The example above is without the second argument. Let's take another number and add a second argument:

num = round ( 6.45892 , 2 )
print ( num )
Result:

alex@alex-pc:~$ /bin/python3 /home/alex/test.py
6.46
As you can see, using the round() function is not difficult at all. Let's look at the following function.

Read also
Igor Dolgov: “After a month of Python intensive, they called me and said: “If you feel you can handle it, join us”
Function int()
This is also a built-in function, which does not uganda telegram data require any imports to work. Using this function is a rather crude way of rounding, which works against all the rules of arithmetic. In essence, this function simply discards all the digits after the decimal point, in other words, it removes the entire fractional part of the number.



num = int ( 6.452 )
print ( num )
As a result we get:

alex@alex-pc:~$ /bin/python3 /home/alex/test.py
6
We get the same result if we take the number 6.9:

num = int ( 6.9 )
print ( num )
Result:

alex@alex-pc:~$ /bin/python3 /home/alex/test.py
6
This method is ideal if you only need the integer part of a number. Next, let's look at the functions from the math module.
Post Reply