Home Java Java-bigdecimal Java bigdecimal valueOf long method

Related Tutorials


 
 

Share on Google+Share on Google+

Java bigdecimal valueOf long method

Advertisement
Example below demonstrates working of bigdecimal class valueOf method. Method returns bigdecimal values.

Java bigdecimal valueOf long method

     

Example below demonstrates working of bigdecimal class valueOf method. Method returns bigdecimal values.  Method converts the long values in to bigdecimal value. Method returns a static bigdecimal object with the specified int scale. 

Syntax for using the method: static BigDecimal longValue(long ln, int i) 
Suppose we have bigdecimal objects x & y & the long variable z & int i;
  then y = x.valueOf(z, i);
System.out.println(y); 

 

Java_bigdecimal_valueOf_long_method.java

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

public class Java_bigdecimal_valueOf_long_method {

  public static void main(String args[]) {

  BigDecimal obj = new BigDecimal(0);

  long ln = 1345444456;
  System.out.println("long value : " + ln + 
  "\nmethod generated result :"
  + obj.valueOf(ln, 2));

  int in = 4545;
  System.out.println("\ninteger value " +
  ": " + in
  "\nmethod generated result" +
  " :" + obj.valueOf(in, 5));

  ln = 2120022;
  System.out.println("\nlong value : " + ln
  "\nmethod generated result " +
  ":" + obj.valueOf(ln, 4));

  in = 256;
  System.out.println("\ninteger value : " + in
  "\nmethod generated result " +
  ":" + obj.valueOf(in, 2));
  }
}

Download the code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 24, 2008

Related Tutorials

Discuss: Java bigdecimal valueOf long method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com