Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Is there a way to diplay a float value 22.19999999998 as 22.2?

Reply
Thread Tools

Is there a way to diplay a float value 22.19999999998 as 22.2?

 
 
Harish Madhavan K
Guest
Posts: n/a
 
      05-07-2004
Hi,
The value retrned from the server is 22.1999999998
How do I display/pirntln this as 22.2 in a gui/console?
Thanks
Harish


 
Reply With Quote
 
 
 
 
Harish Madhavan K
Guest
Posts: n/a
 
      05-07-2004
Forget about this, java.text.NumberFormat is the answer.

"Harish Madhavan K" <(E-Mail Removed)> wrote in message
news:c7g83b$(E-Mail Removed)...
> Hi,
> The value retrned from the server is 22.1999999998
> How do I display/pirntln this as 22.2 in a gui/console?
> Thanks
> Harish
>
>



 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      05-07-2004
Harish Madhavan K wrote:

>Hi,
> The value retrned from the server is 22.1999999998
> How do I display/pirntln this as 22.2 in a gui/console?
>Thanks
>Harish
>

Should be possible with class java.text.DecimalFormat (although much
more can be done with it)
Read
http://java.sun.com/docs/books/tutor...malFormat.html
for examples.

--
Thomas<dot>Fritsch<squiggle>ops<dot>de

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-07-2004
On Fri, 7 May 2004 10:56:43 -0400, "Harish Madhavan K"
<(E-Mail Removed)> wrote or quoted :

> The value retrned from the server is 22.1999999998
> How do I display/pirntln this as 22.2 in a gui/console?


see http://mindprod.com/jgloss/floatingpoint.html

http://mindprod.com/converter.html

You want to convert double or float to String.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Mason Bryant
Guest
Posts: n/a
 
      05-07-2004
"Harish Madhavan K" <(E-Mail Removed)> wrote in message news:<c7g83b$(E-Mail Removed)>...
> Hi,
> The value retrned from the server is 22.1999999998
> How do I display/pirntln this as 22.2 in a gui/console?
> Thanks
> Harish


Does
http://java.sun.com/j2se/1.4.2/docs/...berFormat.html help?
 
Reply With Quote
 
Karl von Laudermann
Guest
Posts: n/a
 
      05-07-2004
"Harish Madhavan K" <(E-Mail Removed)> wrote in message news:<c7g83b$(E-Mail Removed)>...
> Hi,
> The value retrned from the server is 22.1999999998
> How do I display/pirntln this as 22.2 in a gui/console?
> Thanks
> Harish


You could use a NumberFormat to display the value to one decimal place.

fmt = NumberFormat.getNumberInstance();
fmt.setMaximumFractionDigits(1);

double myValue = 22.1999999998;
String valStr = fmt.format(myValue);
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
Weird diplay problem with XSL / XML lucky XML 15 02-23-2007 08:52 AM
Diplay/ Terminal Problems Colin Rodgers Computer Support 7 03-11-2005 03:23 AM
Database Diplay Format m3ckon ASP .Net 1 08-18-2004 11:37 AM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments