Nick [ March 21, 2007: Message edited by: Nick White ]
auvrm papu
Ranch Hand
Joined: Sep 01, 2005
Posts: 105
posted
0
Thanks.
is there a simple function in java doing that already?
for ex: reverse() function for strings already exits..
similary, i was expecting some java api to fetch the decimal part from that given double value..from which I can do my length() operator.
makes sense? [ March 21, 2007: Message edited by: Laxi Rara ]
David McCombs
Ranch Hand
Joined: Oct 17, 2006
Posts: 212
posted
0
This can be done as easily as 2 String method calls. length() of course and for the other look up split().
Be careful of the case where no decimal point exists.
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
sindy lee
Greenhorn
Joined: Aug 05, 2010
Posts: 14
posted
0
I think,you can not do it with "String", for ex.: what about the number "8.0E-5" ?
So i want to ask the same question!
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
4
posted
0
A double does not have a decimal point. It has a mantissa, which always has a single 1 before the radix point, and an exponent, and a sign. You can Google IEEE754 for more details. So "number of places beyond the decimal point" is meaningless. The only floating-point number which actually has a decimal point is BigDecimal. But don't try converting a double to a BigDecimal, otherwise you will get a display with dozens of digits after the decimal point. I believe there are methods in BigDecimal which give you the number of places directly.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
4
posted
0
I earlier wrote:. . . mantissa . . . always has a single 1 before the radix point, . . .
. . . except for values with an absolute value < this, or ±0, or ∞ or "NaN". The 1 in "normal" values is implicit; it isn't actually stored in memory.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How to count the number of digits after decimal point in java?