Related Articles

Related Articles

Getting rounded value of a number in Julia – round() Method
  • Last Updated : 21 Apr, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output:

2
2.0
3.0
0.0
2.0
4.0

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :