Ruby | BigDecimal sign() function
BigDecimal#sign() : sign() is a BigDecimal class method which signs the Big decimal to the nearest integer.
Syntax: BigDecimal.sign()
Parameter: BigDecimal values
Return: signs the Big decimal to the nearest integer.
Example #1 :
# Ruby code for BigDecimal.sign() method # loading library require 'bigdecimal' # declaring bigdecimal a = BigDecimal("10333") # declaring bigdecimal b = -BigDecimal("10") # declaring bigdecimal c = BigDecimal("565") # sign() method puts "BigDecimal example sign : #{a.sign()}\n\n" puts "BigDecimal example sign : #{b.sign()}\n\n" puts "BigDecimal example sign : #{c.sign()}\n\n" |
chevron_right
filter_none
Output :
BigDecimal example sign : 2 BigDecimal example sign : -2 BigDecimal example sign : 2
Example #2 :
# Ruby code for BigDecimal.sign() method # loading library require 'bigdecimal' # declaring bigdecimal a = BigDecimal('43443') # declaring bigdecimal b = BigDecimal('10') # declaring bigdecimal c = BigDecimal('-3') # sign() method puts "BigDecimal example sign : #{a.sign()}\n\n" puts "BigDecimal example sign : #{b.sign()}\n\n" puts "BigDecimal example sign : #{c.sign()}\n\n" |
chevron_right
filter_none
Output :
BigDecimal example sign : 2 BigDecimal example sign : 2 BigDecimal example sign : -2
Recommended Posts:
- Ruby | BigDecimal exp() function
- Ruby | BigDecimal E() function
- Ruby | BigDecimal zero?() function
- Ruby | BigDecimal log() function
- Ruby | BigDecimal quo() function
- Ruby | BigDecimal sin() function
- Ruby | BigDecimal PI() function
- Ruby | BigDecimal cos() function
- Ruby | BigDecimal sub() function
- Ruby | BigDecimal to_s() function
- Ruby | BigDecimal remainder() function
- Ruby | BigDecimal truncate() function
- Ruby | BigDecimal to_d() function
- Ruby | BigDecimal round() function
- Ruby | BigDecimal to_digits() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



