You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Leonardo Quijano Vincenzi <le...@dtqsoftware.com> on 2006/01/21 14:46:14 UTC

Re: tapestry 4 and best layout -

You should actually start new e-mails in a new thread. Lots of people 
"ignore" threaded e-mails for conversations they don't want to see.
And for the common page layout, check the examples for the @Border 
component.

-- 
Ing. Leonardo Quijano Vincenzi
DTQ Software


Korbinian Bachl wrote:
> Hi,
>
> i was wondering what the "best practice" (best for you) for tapestry would
> be do define a common page layout for the whole web app and how to put the
> needed parts together... i mean i really loved (struts-)tiles (but not
> struts itself), as it is just wonderful in that way as it even can get its
> info from any RDBMs meaning it can be used to put things together even in
> CMS with ease...
>
>
> Regards,
>
> Korbinian
>
> PS: i already know the way Kent Tong did it in "Enjoying Webdevelopement
> With Tapestry 4" (Great Book!! -  a shame that EU-citizens cant order it on
> hardpaper) - but i just like to know what other ways would work...
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>   




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ???

Posted by Valdemaras Repšys <de...@gmail.com>.
Hi,

I get c = 3.1639999999999997 with the same code.
Anyways, you should use Double or BigDecimal if you require precise
results on calculations.

Valdemaras

Št, 2006 01 21 07:25 -0800, Gunna Satria rašė:
> Hi All,
>    
>   I tried this code:
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   System.out.println("c = "+c);
>   and the result is,   c = 3.1679999999999997
>   not 3.164 like i expected
>   how come?
>    
>   regards,
>    
>   Gunna
> 
> 
> 		
> ---------------------------------
>  
>  What are the most popular cars?  Find out at Yahoo! Autos


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ???

Posted by Mind Bridge <mi...@yahoo.com>.
The result is absolutely correct. You have to consider the fact that 'b' 
is a manager and weighs more (literally and figuratively).

Gunna Satria wrote:
> Hi All,
>    
>   I tried this code:
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   System.out.println("c = "+c);
>   and the result is,   c = 3.1679999999999997
>   not 3.164 like i expected
>   how come?
>    
>   regards,
>    
>   Gunna
>
>
> 		
> ---------------------------------
>  
>  What are the most popular cars?  Find out at Yahoo! Autos
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ??? (found solution, i think)

Posted by Sergei Dubov <sd...@gmail.com>.
Dude, you really need to pass a String to BigDecimal, not a double, a 
double is still a double.

By the way, this is a Tapestry mailing list... I recommend that you get 
"Java Puzzlers" book written by the real gurus.

http://www.amazon.com/gp/product/032133678X/qid=1137887465/sr=2-1/ref=pd_bbs_b_2_1/002-2850119-9397667?s=books&v=glance&n=283155

This will get you the answers on esoteric questions. gee.

-S.





Gunna Satria wrote:
> Hi All,
>   Thanks for the replies...i really appreciate it
>   I already tried using BigDecimal.. and still the result is not like i expected.
> BigDecimal a = new BigDecimal(3.163);
>   BigDecimal b = new BigDecimal(0.001);
>   BigDecimal c = a.add(b);
>   System.out.println("c = "+c);
>   System.out.println("c db = "+c.doubleValue());
>   and the result is,
>     c = 3.163999999999999811726991705285172429285012185573577880859375
>   c db = 3.1639999999999997
>   finally i found a workaround for this..
>   i use,
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   c = Math.round(c*1000);
>   c = c/1000;
>   double d = (Math.round(c*1000))/1000;
>   System.out.println("c = "+c);
>   System.out.println("d = "+d);
>   here the result for c is correct, 3.164
>   but.... you all may guess that d will yield same result as c, but...
>   you guys are wrong!!!!
>   d is 3.0
>   i have no comment on this.. maybe you guys knew something on this.
>   well... atleast i found a workaround using the round thing,
>   but..
>   that means that i have to change my whole program.... oo gosh..
>   fyi, i'am running the program under sun solaris 8.
>   this is only tip of the iceburg,
>   i'm doing this calculation for gas splitting..
>   so it involves a lof of money...
>   so you guys can imagine that 3.163 and different of 0.001 is important
>   for example,
>   if production = 30000 barrel
>   0.001 * 30000(daily produced oil) * 67 US$ * 30 days = 60300 US$
>   and 30000 is only 10% from total production.
>   But again, thanks for let me sharing the pain :D
>    
>   best regards,
>    
>   Gunna
> 
> 
> 		
> ---------------------------------
> Yahoo! Photos
>  Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: [OT] 3.163 + 0.001 = ??? (finish)

Posted by Gunna Satria <gu...@yahoo.com>.
Okay,
  Thanks for the all solution.
  Yes, sorry for the others, for i had make your inbox full with my stupidity.
   
  best regards,
   
  Gunna

Patrick Casey <pa...@adelphia.net> wrote:
  
The problem is where you're setting the bigdecimal.

BigDecimal a = new BigDecimal(3.163) sets the bigdecimal to the
*double* 3.163. The double is the implied type of any constant set in java
if there isn't enough information available to type it explicitely.

To set the BigDecimal to precisely 3.163, use:

BigDecimal a = new BigDecimal("3.163");
[deleted]
		
---------------------------------
 
 What are the most popular cars?  Find out at Yahoo! Autos

RE: [OT] 3.163 + 0.001 = ??? (finish)

Posted by Gunna Satria <gu...@yahoo.com>.
Okay,
  Thanks for the all solution.
  Yes, sorry for the others, for i had make your inbox full with my stupidity.
   
  best regards,
   
  Gunna

Patrick Casey <pa...@adelphia.net> wrote:
  
The problem is where you're setting the bigdecimal.

BigDecimal a = new BigDecimal(3.163) sets the bigdecimal to the
*double* 3.163. The double is the implied type of any constant set in java
if there isn't enough information available to type it explicitely.

To set the BigDecimal to precisely 3.163, use:

BigDecimal a = new BigDecimal("3.163");
[deleted]
		
---------------------------------
 
 What are the most popular cars?  Find out at Yahoo! Autos

RE: [OT] 3.163 + 0.001 = ??? (found solution, i think)

Posted by Patrick Casey <pa...@adelphia.net>.
	The problem is where you're setting the bigdecimal.

	BigDecimal  a = new BigDecimal(3.163) sets the bigdecimal to the
*double* 3.163. The double is the implied type of any constant set in java
if there isn't enough information available to type it explicitely.

	To set the BigDecimal to precisely 3.163, use:

	BigDecimal a = new BigDecimal("3.163");

	I have to agree a bit with Sergai here; this is pretty basic java
blocking and tacking stuff that doesn't have a lot of relevance to Tapestry.
Additionally, and I can't find a nicer way to say this so sorry about the
way this is going to come out, but if you're seriously lost and confused by
things like the nature of floating point numbers, then you'll definitely
benefit from some time spent on basic java programming before you dive into
a web development framework.

	--- Pat

> -----Original Message-----
> From: Gunna Satria [mailto:gunna_satria@yahoo.com]
> Sent: Saturday, January 21, 2006 3:42 PM
> To: Tapestry users
> Subject: Re: [OT] 3.163 + 0.001 = ??? (found solution, i think)
> 
> Hi All,
>   Thanks for the replies...i really appreciate it
>   I already tried using BigDecimal.. and still the result is not like i
> expected.
> BigDecimal a = new BigDecimal(3.163);
>   BigDecimal b = new BigDecimal(0.001);
>   BigDecimal c = a.add(b);
>   System.out.println("c = "+c);
>   System.out.println("c db = "+c.doubleValue());
>   and the result is,
>     c = 3.163999999999999811726991705285172429285012185573577880859375
>   c db = 3.1639999999999997
>   finally i found a workaround for this..
>   i use,
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   c = Math.round(c*1000);
>   c = c/1000;
>   double d = (Math.round(c*1000))/1000;
>   System.out.println("c = "+c);
>   System.out.println("d = "+d);
>   here the result for c is correct, 3.164
>   but.... you all may guess that d will yield same result as c, but...
>   you guys are wrong!!!!
>   d is 3.0
>   i have no comment on this.. maybe you guys knew something on this.
>   well... atleast i found a workaround using the round thing,
>   but..
>   that means that i have to change my whole program.... oo gosh..
>   fyi, i'am running the program under sun solaris 8.
>   this is only tip of the iceburg,
>   i'm doing this calculation for gas splitting..
>   so it involves a lof of money...
>   so you guys can imagine that 3.163 and different of 0.001 is important
>   for example,
>   if production = 30000 barrel
>   0.001 * 30000(daily produced oil) * 67 US$ * 30 days = 60300 US$
>   and 30000 is only 10% from total production.
>   But again, thanks for let me sharing the pain :D
> 
>   best regards,
> 
>   Gunna
> 
> 
> 
> ---------------------------------
> Yahoo! Photos
>  Ring in the New Year with Photo Calendars. Add photos, events, holidays,
> whatever.



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ??? (found solution, i think)

Posted by Gunna Satria <gu...@yahoo.com>.
Hi All,
  Thanks for the replies...i really appreciate it
  I already tried using BigDecimal.. and still the result is not like i expected.
BigDecimal a = new BigDecimal(3.163);
  BigDecimal b = new BigDecimal(0.001);
  BigDecimal c = a.add(b);
  System.out.println("c = "+c);
  System.out.println("c db = "+c.doubleValue());
  and the result is,
    c = 3.163999999999999811726991705285172429285012185573577880859375
  c db = 3.1639999999999997
  finally i found a workaround for this..
  i use,
  double a = 3.163;
  double b = 0.001;
  double c = a+b;
  c = Math.round(c*1000);
  c = c/1000;
  double d = (Math.round(c*1000))/1000;
  System.out.println("c = "+c);
  System.out.println("d = "+d);
  here the result for c is correct, 3.164
  but.... you all may guess that d will yield same result as c, but...
  you guys are wrong!!!!
  d is 3.0
  i have no comment on this.. maybe you guys knew something on this.
  well... atleast i found a workaround using the round thing,
  but..
  that means that i have to change my whole program.... oo gosh..
  fyi, i'am running the program under sun solaris 8.
  this is only tip of the iceburg,
  i'm doing this calculation for gas splitting..
  so it involves a lof of money...
  so you guys can imagine that 3.163 and different of 0.001 is important
  for example,
  if production = 30000 barrel
  0.001 * 30000(daily produced oil) * 67 US$ * 30 days = 60300 US$
  and 30000 is only 10% from total production.
  But again, thanks for let me sharing the pain :D
   
  best regards,
   
  Gunna


		
---------------------------------
Yahoo! Photos
 Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

Re: [OT] 3.163 + 0.001 = ???

Posted by Sergei Dubov <sd...@gmail.com>.
Pat,

It's Saturday, just go and have a beer.

:-)

-Serge

Patrick Casey wrote:
> 	Huh? A double is a double is a double, regardless of the processor's
> register size, neh? Isn't that one of the guarantees of the JVM?
> 
> 	--- Pat
> 
> 
>>-----Original Message-----
>>From: Sergei Dubov [mailto:sdubov@gmail.com]
>>Sent: Saturday, January 21, 2006 11:12 AM
>>To: Tapestry users
>>Subject: Re: [OT] 3.163 + 0.001 = ???
>>
>>Just switch to AMD 64 CPU, it is more precise than Intel.
>>
>>:-))))
>>
>>Serge.
>>
>>Gunna Satria wrote:
>>
>>>Hi All,
>>>
>>>  I tried this code:
>>>  double a = 3.163;
>>>  double b = 0.001;
>>>  double c = a+b;
>>>  System.out.println("c = "+c);
>>>  and the result is,   c = 3.1679999999999997
>>>  not 3.164 like i expected
>>>  how come?
>>>
>>>  regards,
>>>
>>>  Gunna
>>>
>>>
>>>
>>>---------------------------------
>>>
>>> What are the most popular cars?  Find out at Yahoo! Autos
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: [OT] 3.163 + 0.001 = ???

Posted by Patrick Casey <pa...@adelphia.net>.
	Huh? A double is a double is a double, regardless of the processor's
register size, neh? Isn't that one of the guarantees of the JVM?

	--- Pat

> -----Original Message-----
> From: Sergei Dubov [mailto:sdubov@gmail.com]
> Sent: Saturday, January 21, 2006 11:12 AM
> To: Tapestry users
> Subject: Re: [OT] 3.163 + 0.001 = ???
> 
> Just switch to AMD 64 CPU, it is more precise than Intel.
> 
> :-))))
> 
> Serge.
> 
> Gunna Satria wrote:
> > Hi All,
> >
> >   I tried this code:
> >   double a = 3.163;
> >   double b = 0.001;
> >   double c = a+b;
> >   System.out.println("c = "+c);
> >   and the result is,   c = 3.1679999999999997
> >   not 3.164 like i expected
> >   how come?
> >
> >   regards,
> >
> >   Gunna
> >
> >
> >
> > ---------------------------------
> >
> >  What are the most popular cars?  Find out at Yahoo! Autos
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ???

Posted by Sergei Dubov <sd...@gmail.com>.
Just switch to AMD 64 CPU, it is more precise than Intel.

:-))))

Serge.

Gunna Satria wrote:
> Hi All,
>    
>   I tried this code:
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   System.out.println("c = "+c);
>   and the result is,   c = 3.1679999999999997
>   not 3.164 like i expected
>   how come?
>    
>   regards,
>    
>   Gunna
> 
> 
> 		
> ---------------------------------
>  
>  What are the most popular cars?  Find out at Yahoo! Autos

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ???

Posted by Paul Cantrell <ca...@pobox.com>.
Uh, I that was a just a typo or a copy and paste mistake or  
something. I get the expected result on my JVM, too.

On this subject: IIRC, Tapestry internally uses double instead of  
BigDecimal in its number translator -- even if your final input  
property is declared a BigDecimal or and integer type.

A prize to the first person who can uncover a bug because of this!  
(Your prize is getting to make a JIRA posting.)

P


On Jan 24, 2006, at 4:15 AM, Norbert Sándor wrote:

> Sounds logical to me, too... Because if it would be correct then  
> type "double" would be almost useless!
> Maybe a bug report should be created for the given JVM (with the  
> details of your system) if you are REALLY sure about that result.
>
> Regards,
> Norbi
>
> ----- Original Message ----- From: "Sebastiaan van Erk"  
> <se...@sebster.com>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Tuesday, January 24, 2006 10:54 AM
> Subject: Re: [OT] 3.163 + 0.001 = ???
>
>
>> Hi,
>>
>> I'm replying a few days late, but hopefully it's still useful.
>>
>> I don't understand all the people saying you should use BigDecimal  
>> or saying that this is a double rounding problem. The BigDecimal  
>> solution will work (that's beside the point), but that this is a  
>> double rounding problem is incorrect and your code below *SHOULD*  
>> work.
>>
>> A double has a huge number of digits of precision, about 15 or 16  
>> or so (this is so ridiculously precise that it could store the  
>> circumference of the earth to within 1/1000th of the width of a  
>> human hair precision). Since a double is stored in bits and not in  
>> decimal digits, there is a problem representing decimal numbers  
>> exactly. That is, there may be a small error due to the last bit  
>> only being able to be a 0 or a 1. For example if you only had 2  
>> bits after the decimal point you would only have (in binary) 0.00,  
>> 0.01, 0.10 and 0.11 which are 0, 0.25, 0.5, and .75 in decimal.  
>> Thus any other decimal value would have to be converted to the  
>> closest one of these.
>>
>> However, the last bit being off means you can have a small error  
>> in the 15th digit of precision, not in the 4th!!!
>>
>> A result you could expect, and the result I in fact get when I run  
>> your program is: c = 3.1639999999999997
>>
>> This is the correct result, it is really really terribly close to  
>> 3.164, unlike 3.1679999999999997 which is just plain miles off.
>>
>> I don't have an explanation for your result. It is terribly wrong!  
>> Furthermore, as far as I know, all java virtual machines should  
>> produce the exact same result so you should get the result that I  
>> got above.
>>
>> Greetings,
>> Sebastiaan
>>
>> Gunna Satria wrote:
>>> Hi All,
>>>    I tried this code:
>>>   double a = 3.163;
>>>   double b = 0.001;
>>>   double c = a+b;
>>>   System.out.println("c = "+c);
>>>   and the result is,   c = 3.1679999999999997
>>>   not 3.164 like i expected
>>>   how come?
>>>    regards,
>>>    Gunna
>>>
>>>
>>>
>>> ---------------------------------
>>>  What are the most popular cars?  Find out at Yahoo! Autos
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user- 
>> help@jakarta.apache.org
>>
>>
>>
>>
>>
>> -- 
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.1.375 / Virus Database: 267.14.22/238 - Release Date:  
>> 2006. 01. 23.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ???

Posted by Norbert Sándor <de...@erinors.com>.
Sounds logical to me, too... Because if it would be correct then type 
"double" would be almost useless!
Maybe a bug report should be created for the given JVM (with the details of 
your system) if you are REALLY sure about that result.

Regards,
Norbi

----- Original Message ----- 
From: "Sebastiaan van Erk" <se...@sebster.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Tuesday, January 24, 2006 10:54 AM
Subject: Re: [OT] 3.163 + 0.001 = ???


> Hi,
>
> I'm replying a few days late, but hopefully it's still useful.
>
> I don't understand all the people saying you should use BigDecimal or 
> saying that this is a double rounding problem. The BigDecimal solution 
> will work (that's beside the point), but that this is a double rounding 
> problem is incorrect and your code below *SHOULD* work.
>
> A double has a huge number of digits of precision, about 15 or 16 or so 
> (this is so ridiculously precise that it could store the circumference of 
> the earth to within 1/1000th of the width of a human hair precision). 
> Since a double is stored in bits and not in decimal digits, there is a 
> problem representing decimal numbers exactly. That is, there may be a 
> small error due to the last bit only being able to be a 0 or a 1. For 
> example if you only had 2 bits after the decimal point you would only have 
> (in binary) 0.00, 0.01, 0.10 and 0.11 which are 0, 0.25, 0.5, and .75 in 
> decimal. Thus any other decimal value would have to be converted to the 
> closest one of these.
>
> However, the last bit being off means you can have a small error in the 
> 15th digit of precision, not in the 4th!!!
>
> A result you could expect, and the result I in fact get when I run your 
> program is: c = 3.1639999999999997
>
> This is the correct result, it is really really terribly close to 3.164, 
> unlike 3.1679999999999997 which is just plain miles off.
>
> I don't have an explanation for your result. It is terribly wrong! 
> Furthermore, as far as I know, all java virtual machines should produce 
> the exact same result so you should get the result that I got above.
>
> Greetings,
> Sebastiaan
>
> Gunna Satria wrote:
>> Hi All,
>>    I tried this code:
>>   double a = 3.163;
>>   double b = 0.001;
>>   double c = a+b;
>>   System.out.println("c = "+c);
>>   and the result is,   c = 3.1679999999999997
>>   not 3.164 like i expected
>>   how come?
>>    regards,
>>    Gunna
>>
>>
>>
>> ---------------------------------
>>  What are the most popular cars?  Find out at Yahoo! Autos
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.375 / Virus Database: 267.14.22/238 - Release Date: 2006. 01. 
> 23.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: [OT] 3.163 + 0.001 = ???

Posted by Sebastiaan van Erk <se...@sebster.com>.
Hi,

I'm replying a few days late, but hopefully it's still useful.

I don't understand all the people saying you should use BigDecimal or 
saying that this is a double rounding problem. The BigDecimal solution 
will work (that's beside the point), but that this is a double rounding 
problem is incorrect and your code below *SHOULD* work.

A double has a huge number of digits of precision, about 15 or 16 or so 
(this is so ridiculously precise that it could store the circumference 
of the earth to within 1/1000th of the width of a human hair precision). 
Since a double is stored in bits and not in decimal digits, there is a 
problem representing decimal numbers exactly. That is, there may be a 
small error due to the last bit only being able to be a 0 or a 1. For 
example if you only had 2 bits after the decimal point you would only 
have (in binary) 0.00, 0.01, 0.10 and 0.11 which are 0, 0.25, 0.5, and 
.75 in decimal. Thus any other decimal value would have to be converted 
to the closest one of these.

However, the last bit being off means you can have a small error in the 
15th digit of precision, not in the 4th!!!

A result you could expect, and the result I in fact get when I run your 
program is: c = 3.1639999999999997

This is the correct result, it is really really terribly close to 3.164, 
unlike 3.1679999999999997 which is just plain miles off.

I don't have an explanation for your result. It is terribly wrong! 
Furthermore, as far as I know, all java virtual machines should produce 
the exact same result so you should get the result that I got above.

Greetings,
Sebastiaan

Gunna Satria wrote:
> Hi All,
>    
>   I tried this code:
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   System.out.println("c = "+c);
>   and the result is,   c = 3.1679999999999997
>   not 3.164 like i expected
>   how come?
>    
>   regards,
>    
>   Gunna
> 
> 
> 		
> ---------------------------------
>  
>  What are the most popular cars?  Find out at Yahoo! Autos

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


AW: [OT] 3.163 + 0.001 = ???

Posted by Korbinian Bachl <ko...@whiskyworld.de>.
Hi,

Code:
		BigDecimal a = BigDecimal.valueOf(3.163);
		BigDecimal b = BigDecimal.valueOf(0.001); 
		BigDecimal c = a.add(b);
		System.out.println("a 		= "+a);
		System.out.println("b 		= "+b);
		System.out.println("c 		= "+c);
		System.out.println("c db	= "+c.doubleValue());
		System.out.println("c int	= "+c.intValue());
		System.out.println("c pre 	= "+c.precision()); 

Results:
a 		= 3.163
b 		= 0.0010
c 		= 3.1640
c db		= 3.164
c int		= 3
c pre 	= 5

Depending on your needs, you may choose what you want from BigDecimal, as
its your friend if you have none-int values!

Regards

Korbinian

> -----Ursprüngliche Nachricht-----
> Von: Gunna Satria [mailto:gunna_satria@yahoo.com] 
> Gesendet: Samstag, 21. Januar 2006 16:26
> An: Tapestry users
> Betreff: [OT] 3.163 + 0.001 = ???
> 
> Hi All,
>    
>   I tried this code:
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   System.out.println("c = "+c);
>   and the result is,   c = 3.1679999999999997
>   not 3.164 like i expected
>   how come?
>    
>   regards,
>    
>   Gunna
> 
> 
> 		
> ---------------------------------
>  
>  What are the most popular cars?  Find out at Yahoo! Autos
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: [OT] 3.163 + 0.001 = ???

Posted by Patrick Casey <pa...@adelphia.net>.
	Double is java's implementation of EEE Long Real: 64 bits  

	It encodes things as:
	1 bit for the sign, 
	11 bits for the exponent
	52 bits for the mantissa

	What that means is that any number it encodes is actually a small
math problem that is "solved" to display it for you. These math problems
though don't offer the guarantee that their solution is *exactly the same
as* the number you put in originally. All they guarantee is that it'll be
"pretty damn close".

	Here's a pretty good explanation:

	http://www.nuvisionmiami.com/books/asm/workbook/floating_tut.htm

	The short version though is that there's no guarantee of symmetry
between what you put into a double (or a float) and what you get out.
They'll be *real close* but not necessarily identical.

	That's why if you want precise manipulation of, say, currencies,
*don't use doubles*. Use Bigdecimal instead.

	--- Pat
> -----Original Message-----
> From: Gunna Satria [mailto:gunna_satria@yahoo.com]
> Sent: Saturday, January 21, 2006 7:26 AM
> To: Tapestry users
> Subject: [OT] 3.163 + 0.001 = ???
> 
> Hi All,
> 
>   I tried this code:
>   double a = 3.163;
>   double b = 0.001;
>   double c = a+b;
>   System.out.println("c = "+c);
>   and the result is,   c = 3.1679999999999997
>   not 3.164 like i expected
>   how come?
> 
>   regards,
> 
>   Gunna
> 
> 
> 
> ---------------------------------
> 
>  What are the most popular cars?  Find out at Yahoo! Autos



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


[OT] 3.163 + 0.001 = ???

Posted by Gunna Satria <gu...@yahoo.com>.
Hi All,
   
  I tried this code:
  double a = 3.163;
  double b = 0.001;
  double c = a+b;
  System.out.println("c = "+c);
  and the result is,   c = 3.1679999999999997
  not 3.164 like i expected
  how come?
   
  regards,
   
  Gunna


		
---------------------------------
 
 What are the most popular cars?  Find out at Yahoo! Autos