1package com.tutorialspoint;
2
3import java.math.*;
4
5public class BigDecimalDemo {
6
7 public static void main(String[] args) {
8
9 // create 2 BigDecimal objects
10 BigDecimal bg1, bg2;
11
12 bg1 = new BigDecimal("10");
13 bg2 = new BigDecimal("20");
14
15 //create int object
16 int res;
17
18 res = bg1.compareTo(bg2); // compare bg1 with bg2
19
20 String str1 = "Both values are equal ";
21 String str2 = "First Value is greater ";
22 String str3 = "Second value is greater";
23
24 if( res == 0 )
25 System.out.println( str1 );
26 else if( res == 1 )
27 System.out.println( str2 );
28 else if( res == -1 )
29 System.out.println( str3 );
30 }
31}