Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.
BigDecimal
is an immutable, arbitrary-precision signed decimal number. It contains an arbitrary precision integer unscaled value and a 32-bit integer scale. For example, in the value 10.11, 1011 is the unscaled value, and 2 is the scale. TheBigDecimal
class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion. Read more about theBigDecimal
class here.
The signum
method of the BigDecimal
class retrieves the signum function of a BigDecimal
value.
public int signum()
This method does not take any arguments.
This method returns:
1
if the value of BiDecimal
is greater than zero.
-1
if the value of BiDecimal
is less than zero.
0
if the value of BiDecimal
is equal to zero.
The example below demonstrates how to use the signum
method.
import java.math.BigDecimal;class BigDecimalRemainderExample {public static void main( String args[] ) {BigDecimal val1 = new BigDecimal("10.10");BigDecimal val2 = new BigDecimal("-10.10");BigDecimal val3 = new BigDecimal("0.0");System.out.println("Signum of " + val1 + " :"+ val1.signum());System.out.println("Signum of " + val2 + " : "+ val2.signum());System.out.println("Signum of " + val3 + " : "+ val3.signum());}}
In the above code:
We imported the BigDecimal
class.
We created three BigDecimal
objects, val1
with a value of 10.10
, val2
with a value of -10.10
, and val3
with a value of 0.0
.
We called the signum
method on the created BigDeciaml
objects.
val1
object, we get 1
as the result because val1
> 0.val2
object, we get -1
as the result because val2
< 0.val3
object, we get 0
as the result because val3
= 0.RELATED TAGS
CONTRIBUTOR
Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.