Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Float BigDecimal Question

Thread view: 
morc - 04 Apr 2006 18:28 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.