Ruby | BigDecimal round() function
Last Updated :
05 Dec, 2019
BigDecimal#round() : round() is a BigDecimal class method which rounds the Big decimal to the nearest integer.
Syntax: BigDecimal.round()
Parameter: BigDecimal values
Return: rounds the Big decimal to the nearest integer.
Example #1 :
require 'bigdecimal'
a = 42 . 1 ** 13
b = -BigDecimal( "10" )
c = -( 22 ** 7 . 1 ) * 10
puts "BigDecimal round example : #{a.round()}\n\n"
puts "BigDecimal round example : #{b.round()}\n\n"
puts "BigDecimal round example : #{c.round()}\n\n"
|
Output :
BigDecimal round example : 1305170490200643862528
BigDecimal round example : -10
BigDecimal round example : -33978252068
Example #2 :
require 'bigdecimal'
a = 12 ** 12 - 27
b = BigDecimal( '10' )-( 22 ** 7 . 1 ) ** 10
c = BigDecimal( '-3' )
puts "BigDecimal round example : #{a.round()}\n\n"
puts "BigDecimal round example : #{b.round()}\n\n"
puts "BigDecimal round example : #{c.round()}\n\n"
|
Output :
BigDecimal round example : 8916100448229
BigDecimal round example : -205121100730586399999999999999999999999999999999999999999999999999999999999999999999999999999990
BigDecimal round example : -3
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...