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

|