This content has been marked as final. Show 4 replies
I believe that C#'s decimal is suitable for financial applications since it has a greater precision than other floating point types.
If you need the precision, use the java.math.BigDecimal class, if not, you can probably use Java's primitive double (or the java.lang.Double wrapper).
The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28. -- http://msdn2.microsoft.com/en-us/library/system.decimal.aspx
So you could implement your own version using 4 ints, using longs for intermediate values so you can carry, or by splitting the integer part as the low 48 bits of a pair of longs. Though unless you have a profiler output saying that you can't use BigDecimal, you're better off not re-implementing types from the standard libraries.
Can you u tell me how much memory is allocated for BigDecimal and Wrapper class Double and whether it varies based on value we assign to the BigDecimal and Double objects.?
Can you u tell me how much memory is allocatedNobody can.
and Wrapper class DoubleNobody can.
and whetherYes it does.
it varies based on value we assign to the BigDecimal
and Double objectsNo it doesn't.