Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | BigDecimal sign() function

  • Last Updated : 05 Dec, 2019

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"

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"

Output :

BigDecimal example sign : 2

BigDecimal example sign : 2

BigDecimal example sign : -2




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!