Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Big Decimal Example

// Java Program to illustrate BigDecimal Class
  
import java.math.BigDecimal;
public class BigDecimalExample
{
    public static void main(String[] args) 
    {
        // Create two new BigDecimals
        BigDecimal bd1 = 
               new BigDecimal("124567890.0987654321");
        BigDecimal bd2 = 
               new BigDecimal("987654321.123456789");
          
        // Addition of two BigDecimals
        bd1 = bd1.add(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Multiplication of two BigDecimals
        bd1 = bd1.multiply(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Subtraction of two BigDecimals
        bd1 = bd1.subtract(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Division of two BigDecimals
        bd1 = bd1.divide(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // BigDecima1 raised to the power of 2
        bd1 = bd1.pow(2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Negate value of BigDecimal1
        bd1 = bd1.negate();
        System.out.println("BigDecimal1 = " + bd1);
    }    
}
Comment

Big Decimal Example

// Java Program to illustrate BigDecimal Class
  
import java.math.BigDecimal;
public class BigDecimalExample
{
    public static void main(String[] args) 
    {
        // Create two new BigDecimals
        BigDecimal bd1 = 
               new BigDecimal("124567890.0987654321");
        BigDecimal bd2 = 
               new BigDecimal("987654321.123456789");
          
        // Addition of two BigDecimals
        bd1 = bd1.add(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Multiplication of two BigDecimals
        bd1 = bd1.multiply(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Subtraction of two BigDecimals
        bd1 = bd1.subtract(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Division of two BigDecimals
        bd1 = bd1.divide(bd2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // BigDecima1 raised to the power of 2
        bd1 = bd1.pow(2);
        System.out.println("BigDecimal1 = " + bd1);
  
        // Negate value of BigDecimal1
        bd1 = bd1.negate();
        System.out.println("BigDecimal1 = " + bd1);
    }    
}

/* OUTPUT:
BigDecimal1 = 1112222211.2222222211
BigDecimal1 = 1098491072963113850.7436076939614540479
BigDecimal1 = 1098491071975459529.6201509049614540479
BigDecimal1 = 1112222210.2222222211
BigDecimal1 = 1237038244911605079.77528397755061728521
BigDecimal1 = -1237038244911605079.77528397755061728521
*/
Comment

PREVIOUS NEXT
Code Example
Java :: resultset next method 
Java :: Compare two csv files using java 
Java :: how use a if in java 
Java :: update in spring boot 
Java :: split string to textview in android 
Java :: Retrieve User information in Spring Security 
Java :: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message) 
Java :: all possible substrings of a string java of specific length 
Java :: java resultset to table 
Java :: java create array 
Java :: seek bar 
Java :: java get number at the end of string 
Java :: java number reverse 
Java :: java loop through array 
Java :: enhanced for loop arraylist 
Java :: get current location android 
Java :: procedure java 
Java :: groovy if else 
Java :: Java List Remove Elements using remove() method 
Java :: limit decimals java 
Java :: java final modifier on method 
Java :: java how to create subclass 
Java :: java tree traversal 
Java :: adding watermark to excel 
Java :: how do you handle exceptions in java 
Java :: enum class in java 
Java :: android studio tabbed activity 
Java :: method overriding java 
Java :: java evaluate two expressions in if statemenmt 
Java :: preset arraylist java 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =