posted 16 years ago

I think you could use DecimalFormat class. I think it is in java.util.

Here's an example of it in a book I'm looking at:

DecimalFormat twoDigits= new DecimalFormat("#0.00");

and then there is a fomat(),

so twoDigits.format(the number goes here);

I'm sorry if that isn't a good explanantion. Check out that package though. I would explain it better if I had more time.

Here's an example of it in a book I'm looking at:

DecimalFormat twoDigits= new DecimalFormat("#0.00");

and then there is a fomat(),

so twoDigits.format(the number goes here);

I'm sorry if that isn't a good explanantion. Check out that package though. I would explain it better if I had more time.

posted 16 years ago

Or you could use the java.math.BigDecimal class,

java.math.BigDecimal aBigDecimal = new java.math.BigDecimal(10.35009);

java.math.BigDecimal anotherBigDecimal = new java.math.BigDecimal(11.4765);

aBigDecimal = aBigDecimal.setScale(2, java.math.BigDecimal.ROUND_HALF_UP);

anotherBigDecimal = anotherBigDecimal.setScale(2, java.math.BigDecimal.ROUND_HALF_UP);

Julio Lopez

M-Group Systems

java.math.BigDecimal aBigDecimal = new java.math.BigDecimal(10.35009);

java.math.BigDecimal anotherBigDecimal = new java.math.BigDecimal(11.4765);

aBigDecimal = aBigDecimal.setScale(2, java.math.BigDecimal.ROUND_HALF_UP);

anotherBigDecimal = anotherBigDecimal.setScale(2, java.math.BigDecimal.ROUND_HALF_UP);

Julio Lopez

M-Group Systems

Don't get me started about those stupid light bulbs. |