Ruby Float round() method with example Last Updated : 08 Jan, 2020 Comments Improve Suggest changes Like Article Like Report round() is a float class method which return a float value rounded to the nearest value with n digits decimal digits precision. Syntax: float.round() Parameter: float value as argument Return: Float value rounded to nearest precision If precision is -ve : integer with at least ndigits.abs trailing zeros If ndigits is +ve : a floating-point number, otherwise integer Example #1 : Ruby # Ruby code for round() method # declaring float value a = 0.767 # declaring float value b = 2999.011 # rounding the float value puts "rounding a : #{a.round}\n\n" # rounding the float value puts "rounding b : #{b.round}\n\n" Output : rounding a : 1 rounding b : 2999 Example #2 : Ruby # Ruby code for round() method # declaring float value a = 0.767 # declaring float value b = 2999.011 # declaring float value c = 2.0000 # rounding the float value puts "round a : #{a.round(2)}\n\n" # rounding the float value puts "round b : #{b.round(-2)}\n\n" # rounding the float value puts "round c : #{c.round(0)}\n\n" Output : round a : 0.77 round b : 3000 round c : 2 Comment More infoAdvertise with us Next Article Ruby Float round() method with example M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Float-class Similar Reads Ruby Float to_r() method with example Float to_r() is a float class method which return a rational form of the float value. Syntax: float.to_r() Parameter: float value as argument Return: Rational form representation of the float value. Example #1 : Ruby # Ruby code for to_r() method # Initializing values a = 2.0 b = 9.99991 # Printing 1 min read Ruby Float modulo() method with example Float modulo() is a float class method which return the remainder value on dividing two float values. Syntax: float.modulo() Parameter: remainder value from the operation p/q Return: Modulo i.e. Remainder Example #1: Example for modulo() method Ruby # Ruby program for modulo() method # Initilizig va 1 min read Ruby Float rationalize() method with example Float rationalize() is a float class method which return the simple rational form (p/q) of a float value. Syntax: float.rationalize() Parameter: float value as argument Return: Simple approximation value Example #1: Ruby # Ruby program for rationalize() method # Initialize value a = 0.767 b = 2999.0 1 min read Ruby Float arg() method with example Float arg() is a float class method which works on float values and works differently for both positive and negative values. Syntax: float.arg() Parameter: float value which is to be checked Return: return 0 for positive values. Otherwise pi(3.141592653589793) Example #1: Ruby # Ruby code for arg() 1 min read Ruby Float fdiv() method with example Float fdiv() is a float class method which return a division value of the form p/q. Syntax: float.fdiv() Parameter: values to divide - p and q Return: Division value - Quotient Example #1: Ruby # Ruby program for fdiv() method # Initializing value a = 2.0.numerator() # returning machine dependent re 1 min read Like