Open In App

Getting rounded value of a number in Julia – round() Method

Last Updated : 21 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The round() is an inbuilt function in julia which is used to round the specified number in different ways which are illustrated below-

  • The default round process is done to the nearest integer, with ties (fractional values of 0.5) being rounded to the nearest even integer.
  • The specified value x is rounded to an integer value and returns a value of the given type T or of the same type of x.
  • If the digits keyword parameter is given, it rounds to the specified number of digits after the decimal place (or before if negative), in the given base.
  • If the sigdigits keyword parameter is given, it rounds to the specified number of significant digits, in the given base.

Syntax:
round(x)
round(T, x)
round(x, digits::Integer, base)
round(x, sigdigits::Integer, base)

Parameters:

  • x: Specified number
  • T: Specified number type
  • digits: Specified digit values
  • base: Specified base in which results are coming
  • sigdigits: Specified significant digits

Returns: It returns the rounded value of the specified number.

Example 1:




# Julia program to illustrate 
# the use of round() method
  
# Getting the rounded values
println(round(2))
println(round(2.3))
println(round(2.9))
println(round(0.5))
println(round(2.5))
println(round(3.5))


Output:

2
2.0
3.0
0.0
2.0
4.0

Example 2:




# Julia program to illustrate 
# the use of round() method
  
# Getting the rounded values
println(round(pi; digits = 3))
println(round(56.7685; digits = 3))
println(round(pi; digits = 3, base = 2))
println(round(55.98634; digits = 3, base = 2))
println(round(324.675; sigdigits = 2))
println(round(232.97634; sigdigits = 4, base = 2))


Output:



Similar Reads

Julia continue Keyword | Continue iterating to next value of a loop in Julia
Keywords in Julia are predefined words that have a definite meaning to the compiler. These keywords can’t be used to name variables. 'continue' keyword in Julia skips the statement immediately after the continue statement. Whenever the continue keyword is executed, the compiler immediately stops iterating over further values and sends the execution
1 min read
Getting the absolute value of a number in Julia - abs() Method
The abs() is an inbuilt function in julia which is used to return the absolute value of the specified number x. Syntax: abs(x) Parameters: x: Specified value. Returns: It returns the absolute value of the specified number x. Example 1: # Julia program to illustrate # the use of abs() method # Getting absolute value of the # specified number x print
1 min read
Getting ceiling value of x in Julia - ceil() Method
The ceil() is an inbuilt function in julia which is used to return the nearest integral value greater than or equal to the specified value x. Syntax: ceil(x) Parameters: x: Specified value. Returns: It returns the nearest integral value greater than or equal to the specified value x. Example 1: # Julia program to illustrate # the use of ceil method
1 min read
Getting floor value of x in Julia - floor() Method
The floor() is an inbuilt function in julia which is used to return the nearest integral value less than or equal to the specified value x. Syntax: floor(x) Parameters: x: Specified value. Returns: It returns the nearest integral value less than or equal to the specified value x. Example 1: # Julia program to illustrate # the use of floor() method
1 min read
Getting the minimum value from a list in Julia - min() Method
The min() is an inbuilt function in julia which is used to return the minimum value of the parameters. Syntax: min(x, y, ...) Parameters: x: Specified 1st value. y: Specified 2nd value and so on. Returns: It returns the minimum value of the parameters. Example 1: # Julia program to illustrate # the use of min() method # Getting the minimum value of
1 min read
Getting key value pairs of a dictionary in Julia - pairs() Method
The pairs() is an inbuilt function in julia which is used to return an iterator over key=>value pairs for the specified collection that maps a set of keys to a set of values. This includes arrays, where the keys are the array indices. Syntax: pairs(collection) or pairs(IndexStyle(A), A) Parameters: collection: Specified collection. IndexStyle(A)
1 min read
Getting the maximum value from a list in Julia - max() Method
The max() is an inbuilt function in julia which is used to return the maximum value of the parameters. Syntax: max(x, y, ...) Parameters: x: Specified 1st value. y: Specified 2nd value and so on. Returns: It returns the maximum value of the parameters. Example 1: # Julia program to illustrate # the use of max() method # Getting the maximum value of
1 min read
Getting the nearest integral value of x in Julia - trunc() Method
The trunc() is an inbuilt function in julia which is used to return the nearest integral value of the same type as the specified value x whose absolute value is less than or equal to x. Syntax: trunc(x) Parameters: x: Specified value. Returns: It returns the nearest integral value of the same type as the specified value x whose absolute value is le
1 min read
Getting square of absolute value in Julia - abs2() Method
The abs2() is an inbuilt function in julia which is used to return square of the absolute value of the specified number x. Syntax: abs2(x) Parameters: x: Specified value. Returns: It returns square of the absolute value of the specified number x. Example 1: # Julia program to illustrate # the use of abs2() method # Getting square of absolute value
1 min read
Getting the remainder value after division in Julia - mod() Method
The mod() is an inbuilt function in julia which is used to return remainder when the specified dividend is divided by divisor. Syntax: mod(x, y) Parameters: x: Specified dividend. y: Specified divisor. Returns: It returns remainder when the specified dividend is divided by divisor. Example 1: # Julia program to illustrate # the use of mod() method
1 min read
Article Tags :