java.lang.Object
java.lang.Number
java.math.BigDecimal
- All Implemented Interfaces:
- Serializable, Comparable<BigDecimal>
- See Also:
- Top Examples, Source Code,
movePointRight
, movePointLeft
, round
, setScale
, ulp, specified algorithm, floor, MathContext.UNLIMITED
, RoundingMode.HALF_UP
, ROUND_HALF_UP
, toString()
, BigInteger
,
SortedMap
,
SortedSet
public BigDecimal abs()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1480]Display float number in differnt Locale
By vamshi vamshikrishna1 { at } yahoo { dot } com on 2005/07/13 23:20:51 Rate
float mynumber = 10000000.4875f;
NumberFormat form;
form=NumberFormat.getInstance ( new Locale ( "EN","Locale.UK" ) ) ;
BigDecimal bd=new BigDecimal ( mynumber ) ;
System.out.println ( bd.setScale ( 3,BigDecimal.ROUND_HALF_UP ) ) ;
public BigDecimal abs(MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal add(BigDecimal augend)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[656]Add two big numbers
By Anonymous on 2005/04/25 15:30:20 Rate
// add two big numbers
// submitted by DPB from IST-149 Java 1 NVCC class on Feb 7, 2004...
// The output produced will be:
// big1=123456789 big2=111111111 sum=234567900
public static void addTest ( )
{
BigDecimal big1 = new BigDecimal ( 123456789.0D ) ;
BigDecimal big2 = new BigDecimal ( 111111111.0D ) ;
BigDecimal sum = new BigDecimal ( 0.0D ) ;
sum = big1.add ( big2 ) ; // sum = big1 + big2;
System.out.println ( "big1=" + big1 + " big2=" + big2 + " sum=" + sum ) ;
}
public BigDecimal add(BigDecimal augend,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(char[] in)
- See Also:
- NumberFormatException,
BigDecimal(String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(char[] in,
int offset,
int len)
- See Also:
- NumberFormatException,
BigDecimal(String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(char[] in,
int offset,
int len,
MathContext mc)
- See Also:
- NumberFormatException, ArithmeticException,
BigDecimal(String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(char[] in,
MathContext mc)
- See Also:
- NumberFormatException, ArithmeticException,
BigDecimal(String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(double val)
- See Also:
- NumberFormatException,
valueOf(double)
, BigDecimal(String)
, Double.toString(double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[173]A BigDecimal rounding procedure
By mail { at } wlawson { dot } com on 2003/08/25 19:36:27 Rate
java.math.BigDecimal round_hfinal = new java.math.BigDecimal ( hfinal ) ;
round_hfinal = round_hfinal.setScale ( 4, java.math.BigDecimal.ROUND_HALF_UP ) ;
[405]_
By Anonymous on 2003/09/20 09:50:01 Rate
BigDecimal bd = new BigDecimal ( 0,49 ) ;
System.out.print ( bd ) ;
public BigDecimal(double val,
MathContext mc)
- See Also:
- NumberFormatException, ArithmeticException,
BigDecimal(double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1865]Limiting the decimals in BigDecimal class
By Sagar Deshpande sagard79 { at } gmail { dot } com on 2007/02/03 15:12:56 Rate
public void giveRaise ( float raise ) {
MathContext temp = new MathContext ( 2 ) ;
double sal = this.salary.doubleValue ( ) ;
sal = sal * raise;
this.salary = this.salary.add ( new BigDecimal ( sal,temp ) ) ;
}
public BigDecimal(int val)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(int val,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(String val)
- See Also:
- NumberFormatException,
BigDecimal(double)
, Double.toString(double)
, Float.toString(float)
, Character.digit(char, int)
, Character.isDigit(char)
, Integer.MAX_VALUE
, Integer.MIN_VALUE
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[338]Convert Integer to BigDecimal
By Anonymous on 2003/08/07 15:18:49 Rate
ttlRest += 1;
strTtlRest = Integer.toString ( ttlRest ) ;
BigDecimal tmpTtlRest;
tmpTtlRest = BigDecimal.valueOf ( strTtlRest ) ;
[515]Add 3 BigDecimal
By sonja_999 { at } hotmail { dot } com on 2003/11/15 07:56:55 Rate
import java.math.BigDecimal.*;
public class BigDecimal {
public BigDecimal ( double bd ) {
}
public BigDecimal add ( BigDecimal num )
{
return num;
}
public static void main ( String [ ] args ) {
BigDecimal bd = new BigDecimal ( 100.01 ) ;
BigDecimal bd2 = new BigDecimal ( 100.00005 ) ;
BigDecimal bd3= new BigDecimal ( 100.00995 ) ;
bd = bd.add ( bd2.add ( bd3 ) ) ;
// System,out.obd.
}
}
public BigDecimal(String val,
MathContext mc)
- See Also:
- NumberFormatException, ArithmeticException,
BigDecimal(String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(BigInteger val)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(BigInteger unscaledVal,
int scale)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(BigInteger unscaledVal,
int scale,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(BigInteger val,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(long val)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal(long val,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public byte byteValueExact()
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int compareTo(Object o)
- See Also:
Comparable
, compareTo(java.math.BigDecimal)
, ClassCastException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[798]Use JOptionPane
By Anonymous on 2005/05/09 03:54:07 Rate
import javax.swing.JOptionPane;
import java.lang.String;
public class DadosTexto
{
public static void main ( String args [ ] )
{
String TextEntr;
int numVogais , numCons, numEspac, eBrc, eVog, igual ;
String Vogais [ ] = { "a","e","i","o","u","A","E","O","U" } ;
char ch;
numEspac = 0;
numVogais= 0;
numCons = 0;
for ( int i=0; i < 10; i++ ) {
TextEntr = JOptionPane.showInputDialog ( "Digite o texto a ser analisado:" ) ;
JOptionPane.showMessageDialog ( null,"Seu texto digitado ?? "+TextEntr ) ;
eBrc = 0;
eVog = 0;
for ( int j=0; j < TextEntr.length ( ) ;j++ ) {
ch = TextEntr.charAt ( j ) ;
igual = ch.compareTo ( " " ) ;
if ( igual==0 ) {
numEspac++;
eBrc = 1;
}
else {
for ( int jvg=0; jvg < 9;jvg++ ) {
igual = ch.compareTo ( Vogais [ jvg ] ) ; //onde strC um String que cont??m a letra "A"
if ( igual==0 ) {
{
numVogais++;
jvg = 8;
eVog = 1;
System.out.println ( ch+"?? vogal" ) ;
}
}
}
}
if ( eBrc = 0 && eVog = 0 ) {
numCons++;
}
JOptionPane.showMessageDialog ( null,"O texto digitado tem "+ numCons+" consoantes , "+
numVogais+" vogais e "+numEspac+" espa??os em branco." ) ;
}
}
}
}
public int compareTo(BigDecimal val)
- See Also:
- Comparable, compareTo
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal divide(BigDecimal divisor)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal divide(BigDecimal divisor,
int roundingMode)
- See Also:
ROUND_UNNECESSARY
, ROUND_HALF_EVEN
, ROUND_HALF_DOWN
, ROUND_HALF_UP
, ROUND_FLOOR
, ROUND_CEILING
, ROUND_DOWN
, ROUND_UP
, IllegalArgumentException, ArithmeticException, divide(BigDecimal, RoundingMode)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal divide(BigDecimal divisor,
int scale,
int roundingMode)
- See Also:
ROUND_UNNECESSARY
, ROUND_HALF_EVEN
, ROUND_HALF_DOWN
, ROUND_HALF_UP
, ROUND_FLOOR
, ROUND_CEILING
, ROUND_DOWN
, ROUND_UP
, IllegalArgumentException, ArithmeticException, divide(BigDecimal, int, RoundingMode)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[382]BigDecimal division
By Anonymous on 2003/10/30 16:41:28 Rate
BigDecimal oldShipCharge = new BigDecimal ( 30.00 ) ;
BigDecimal newShipCharge = new BigDecimal ( 10.00 ) ;
BigDecimal ratio = newShipCharge.divide (
oldShipCharge, 10, BigDecimal.ROUND_HALF_EVEN ) ;
[713]_
By Anonymous on 2004/03/30 10:20:02 Rate
10.divide ( java.math.BigDecimal,3,2 )
public BigDecimal divide(BigDecimal divisor,
int scale,
RoundingMode roundingMode)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal divide(BigDecimal divisor,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal divide(BigDecimal divisor,
RoundingMode roundingMode)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal[] divideAndRemainder(BigDecimal divisor)
- See Also:
remainder(java.math.BigDecimal, java.math.MathContext)
, divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
, ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal[] divideAndRemainder(BigDecimal divisor,
MathContext mc)
- See Also:
remainder(java.math.BigDecimal, java.math.MathContext)
, divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
, ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal divideToIntegralValue(BigDecimal divisor)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal divideToIntegralValue(BigDecimal divisor,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double doubleValue()
- See Also:
- Number,
Double.POSITIVE_INFINITY
, Double.NEGATIVE_INFINITY
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean equals(Object x)
- See Also:
hashCode()
, compareTo(java.math.BigDecimal)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public float floatValue()
- See Also:
- Number,
Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int hashCode()
- See Also:
equals(Object)
, Object
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int intValue()
- See Also:
- Number
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int intValueExact()
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public long longValue()
- See Also:
- Number
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public long longValueExact()
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal max(BigDecimal val)
- See Also:
compareTo(java.math.BigDecimal)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal min(BigDecimal val)
- See Also:
compareTo(java.math.BigDecimal)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal movePointLeft(int n)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal movePointRight(int n)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal multiply(BigDecimal multiplicand)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal multiply(BigDecimal multiplicand,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal negate()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[105]Various BigDecimal operations
By Anonymous on 2002/10/18 18:00:05 Rate
public void calculateImagine ( BigDecimal a,BigDecimal b, BigDecimal c ) {
BigDecimal discriminant = getDiscriminantExact ( a,b,c ) ;
BigDecimal two = new BigDecimal ( "2.0" ) ;
BigDecimal x = ( b.negate ( ) ) .divide ( a.multiply ( two ) ,30,BigDecimal.ROUND_HALF_UP ) ;
BigDecimal y = sqrt ( discriminant.negate ( ) ) .divide ( a.multiply ( two ) ,30,BigDecimal.ROUND_HALF_UP ) ;
c2.setSpecial ( correctScale ( x.negate ( ) ) .toString ( ) +"+i*"+correctScale ( y.negate ( ) ) .toString ( ) ,
correctScale ( x.negate ( ) ) .toString ( ) +"-i*"+correctScale ( y.negate ( ) ) .toString ( ) ) ;
}
public BigDecimal negate(MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final BigDecimal ONE
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal plus()
- See Also:
negate()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal plus(MathContext mc)
- See Also:
round(MathContext)
, ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal pow(int n)
- See Also:
- ArithmeticException,
ONE
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal pow(int n,
MathContext mc)
- See Also:
- ArithmeticException,
ONE
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int precision()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal remainder(BigDecimal divisor)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal remainder(BigDecimal divisor,
MathContext mc)
- See Also:
divideToIntegralValue(java.math.BigDecimal, java.math.MathContext)
, ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal round(MathContext mc)
- See Also:
plus(MathContext)
, ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int ROUND_CEILING
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int ROUND_DOWN
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[206]Round to two decimal places
By Anonymous on 2004/06/08 11:04:33 Rate
//round to two decimal places
import java.math.*;
public class RoundTest {
public static void main ( String [ ] args ) {
BigDecimal bd = new BigDecimal ( 1234.5678 ) ;
bd = bd.setScale ( 2, BigDecimal.ROUND_DOWN ) ;
System.out.println ( bd ) ;
}
}
public static final int ROUND_FLOOR
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int ROUND_HALF_DOWN
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int ROUND_HALF_EVEN
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int ROUND_HALF_UP
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int ROUND_UNNECESSARY
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int ROUND_UP
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int scale()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal scaleByPowerOfTen(int n)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal setScale(int newScale)
- See Also:
setScale(int, RoundingMode)
, setScale(int, int)
, ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal setScale(int newScale,
int roundingMode)
- See Also:
ROUND_UNNECESSARY
, ROUND_HALF_EVEN
, ROUND_HALF_DOWN
, ROUND_HALF_UP
, ROUND_FLOOR
, ROUND_CEILING
, ROUND_DOWN
, ROUND_UP
, IllegalArgumentException, ArithmeticException, setScale(int, RoundingMode)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[855]Change BigDecimal scale
By a on 2005/04/29 11:42:11 Rate
balance.setScale ( 2, BigDecimal.ROUND_HALF_UP ) ;
public BigDecimal setScale(int newScale,
RoundingMode roundingMode)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public short shortValueExact()
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int signum()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal stripTrailingZeros()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal subtract(BigDecimal subtrahend)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal subtract(BigDecimal subtrahend,
MathContext mc)
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final BigDecimal TEN
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigInteger toBigInteger()
- See Also:
toBigIntegerExact()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigInteger toBigIntegerExact()
- See Also:
- ArithmeticException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toEngineeringString()
- See Also:
- string constructor,
toString()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toPlainString()
- See Also:
toEngineeringString()
, toString()
, string constructor
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toString()
- See Also:
BigDecimal(java.lang.String)
, Character.forDigit(int, int)
, Object, setScale
, toEngineeringString()
, NumberFormat
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigDecimal ulp()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public BigInteger unscaledValue()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static BigDecimal valueOf(double val)
- See Also:
- NumberFormatException,
Double.toString(double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static BigDecimal valueOf(long val)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static BigDecimal valueOf(long unscaledVal,
int scale)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final BigDecimal ZERO
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples