Java bigdecimal valueOf long example

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.
Syntax for using the method: static BigDecimal longValue(long ln)
Suppose we have bigdecimal objects x & y & the long variable z;
then y = x.valueOf(z);
System.out.println(y);
Java_bigdecimal_valueOf_long.java
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
public class Java_bigdecimal_valueOf_long {
public static void main(String args[]) {
BigDecimal obj = new BigDecimal(0);
long ln = 1256953443;
System.out.println("long value : " + ln +
"\nmethod generated result :"
+ obj.valueOf(ln));
int in = 120;
System.out.println("\ninteger value : "
+ in
+ "\nmethod generated result :"
+ obj.valueOf(in));
ln = 30022543;
System.out.println("\nlong value : " + ln
+ "\nmethod generated result :"
+ obj.valueOf(ln));
in = 256;
System.out.println("\ninteger value : " + in
+ "\nmethod generated result :"
+ obj.valueOf(in));
}
}
|
Download
the code

|