Hi Ekim,

Here's some more detail on your second problem.

Ekim wrote:

> My 2nd problem concerns rounding a double-number. I want to round a number

> like "40.745043" to "40.75", so that it is rounded to 2 digits after the

> decimal point.
The 'double' data type contains binary floating-point numbers rather

than decimal floating-point numbers. While 40.75 does happen to be

directly representable as a binary floating-point value (.01), the

general case of rounding a binary floating-point number to two decimal

digits is not even possible, since the floating-point number often won't

be able to exactly represent that value.

Depending on your application, though, there are solutions. For

example:

1. If this is just for display purposes, then you can use DecimalFormat

to get a rounded String. That works because the target type is String,

not double.

2. For intermediate results that need to be rounded (as required, for

example, in a number of financial calculations), a better choice is

often the BigDecimal class or a fixed-point representation using an int

(or long) and a constant factor -- for example, the integer 12345 might

be used to represent $123.45.

--

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer

MindIQ Corporation