hey,
I have float values that look something like this when they are
printed:
6.0E-4
7.0E-4
I don't want them to be like this I want them to be normalized with 4
decimal places. I've been told BigDecimal class is what i need however
ive beenr eading hte documentation and i don't understand how to use
this class.
If anybody can show me how to do this it would be greatly appreciated.
Thanks in advance.
-morc
Googmeister - 04 Apr 2006 18:37 GMT
> hey,
>
[quoted text clipped - 7 lines]
> ive beenr eading hte documentation and i don't understand how to use
> this class.
If using Java >= 1.5, System.out.printf() might be the easiest
solution.
morc - 04 Apr 2006 18:44 GMT
It's done in .jsp.
I've been told that BigDecimal is what i need to use. However im very
unclear on how this class works. The documentation is fuzzy to me. If
anyone knows how to do this please help me.
thanks again
-morc
Thomas Weidenfeller - 04 Apr 2006 19:14 GMT
> I don't want them to be like this I want them to be normalized with 4
> decimal places. I've been told BigDecimal class is what i need
You got bad advice - assuming you really just asked for output
formating. If you want to have more precision, BigDecimal might indeed
be what you want.
If you want to stick with doubles or floats, use java.text.DecimalFormat
or the new System.out.printf() in 1.5.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
jhr - 04 Apr 2006 19:42 GMT
If this is truely what you want, and it isn't mearly formatting, then
create your BigDecimal as such:
new BigDecimal(6, new MathContext(4));
Roedy Green - 04 Apr 2006 22:35 GMT
>I have float values that look something like this when they are
>printed:
[quoted text clipped - 5 lines]
>ive beenr eading hte documentation and i don't understand how to use
>this class.
you don't need BigDecimal since your numbers are not unusually Large.
You need simply to format your numbers. See
http://mindprod.com/applets/converter.html
for how. You are trying to convert double => String.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Remon van Vliet - 05 Apr 2006 02:02 GMT
>>I have float values that look something like this when they are
>>printed:
[quoted text clipped - 10 lines]
> http://mindprod.com/applets/converter.html
> for how. You are trying to convert double => String.
Doesnt that code still produce mantisse/exponent formatted values?
Roedy Green - 05 Apr 2006 02:06 GMT
On Wed, 5 Apr 2006 03:02:45 +0200, "Remon van Vliet"
<remon@exmachina.nl> wrote, quoted or indirectly quoted someone who
said :
>Doesnt that code still produce mantisse/exponent formatted values?
It depends what you choose for your mask.
see http://mindprod.com/jgloss/decimalformat.html
for details.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.