List of usage examples for java.math BigDecimal BigDecimal
public BigDecimal(long val)
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("123.000"); BigDecimal bg2 = new BigDecimal("12300"); BigDecimal bg3 = bg1.scaleByPowerOfTen(3); BigDecimal bg4 = bg2.scaleByPowerOfTen(-3); String str1 = bg1 + " raised to 10 power 3 is " + bg3; String str2 = bg2 + " raised to 10 power -3 is " + bg4; System.out.println(str1);//from w w w . ja v a 2 s . com System.out.println(str2); }
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("123"); BigDecimal bg2 = new BigDecimal("123.50"); BigDecimal bg3 = new BigDecimal("123.80"); int i1 = bg1.hashCode(); int i2 = bg2.hashCode(); int i3 = bg3.hashCode(); System.out.println(i1);/*from w w w . j av a2 s .co m*/ System.out.println(i2); System.out.println(i3); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BigDecimal bd1 = new BigDecimal("123456789.0123456890"); // Create via a long BigDecimal bd2 = BigDecimal.valueOf(123L); bd1 = bd1.subtract(bd2);// w w w . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("12.345"); BigDecimal bg2 = new BigDecimal("20.123"); // print bg1 and bg2 value System.out.println("Object Value is " + bg1); System.out.println("Augend value is " + bg2); // perform add operation on bg1 with augend bg2 BigDecimal bg3 = bg1.add(bg2); // print bg3 value System.out.println("Result is " + bg3); }
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("235.000"); BigDecimal bg2 = new BigDecimal("23500"); // assign the result of stripTrailingZeros method to bg3, bg4 BigDecimal bg3 = bg1.stripTrailingZeros(); BigDecimal bg4 = bg2.stripTrailingZeros(); String str1 = bg1 + " after removing trailing zeros " + bg3; String str2 = bg2 + " after removing trailing zeros " + bg4; // print bg3, bg4 values System.out.println(str1);//from w w w. j a v a 2s. c o m System.out.println(str2); }
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("123.0"); BigDecimal bg2 = new BigDecimal("-1.123"); // assign the result of scale on bg1, bg2 to i1,i2 int i1 = bg1.scale(); int i2 = bg2.scale(); String str1 = "The scale of " + bg1 + " is " + i1; String str2 = "The scale of " + bg2 + " is " + i2; // print the values of i1,i2; System.out.println(str1);// w ww. j a v a2s .com System.out.println(str2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BigDecimal bd1 = new BigDecimal("123456789.0123456890"); // Create via a long BigDecimal bd2 = BigDecimal.valueOf(123L); bd1 = bd1.divide(bd2, BigDecimal.ROUND_UP); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BigDecimal bd1 = new BigDecimal("123456789.0123456890"); // Create via a long BigDecimal bd2 = BigDecimal.valueOf(123L); bd1 = bd1.multiply(bd2);//from ww w .ja v a2 s .c om }
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("123.234"); BigDecimal bg2 = new BigDecimal("523"); // assign the result of precision of bg1, bg2 to i1 and i2 int i1 = bg1.precision(); int i2 = bg2.precision(); String str1 = "The precision of " + bg1 + " is " + i1; String str2 = "The precision of " + bg2 + " is " + i2; // print the values of i1, i2 System.out.println(str1);//ww w.ja va 2s . c om System.out.println(str2); }
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("235"); BigDecimal bg2 = new BigDecimal("4364"); // assign the short value of bg1 and bg2 to s1,s2 respectively short s1 = bg1.shortValueExact(); short s2 = bg2.shortValueExact(); String str1 = "Exact short value of " + bg1 + " is " + s1; String str2 = "Exact short value of " + bg2 + " is " + s2; // print s1,s2 values System.out.println(str1);//from ww w. j a v a2s . c om System.out.println(str2); }