You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ted Steen <te...@gmail.com> on 2005/09/01 23:39:57 UTC

Decimal rounding problems when working with currency.

Hi all!

I need to work with BigDecimal in order to represent decimal numbers
with greater precision than float.

If I need to store the (float) number 27.9 in a BigDecimal it
transforms into 27.89999999999999857891452847...

In tapestry I have my @TextField with translator:number
tied to a property "public abstract BigDecimal getAmount();"
problem is that tapestry seem to store 27.9 in a float (or maybe
double) before storing it in the BigDecimal which mess up the number.
:(

Now are there a translator for BigDecimal, should I write my own
translator or should I re-thing the whole thing?


-- 
/ted

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


Re: Decimal rounding problems when working with currency.

Posted by Yves Sy <yv...@gmail.com>.
Any plans from the Tapestry team to include this (
http://issues.apache.org/jira/browse/TAPESTRY-817) in the core tapestry
codebase?

I'd say its a pretty basic requirement and I'm actually surprised it isn't
part of Tapestry yet.

Regards,
-Yves-

On 9/2/05, Paul Ferraro <pm...@columbia.edu> wrote:
>
> The NumberTranslator internally uses java.text.DecimalFormat to
> parse/format numbers.  Unfortunately, DecimalFormat is only capable of
> parsing/formatting numbers with at most double precision or smaller.
> To work with BigDecimal (or BigInteger for that matter) you will need to
> write your own Translator implementation.  Contribute your
> implementation to the tapestry.form.translator.Translators configuration
> point and you'll be able to leverage the translator binding prefix.
>
> Paul
>
> Ted Steen wrote:
>
> >Hi all!
> >
> >I need to work with BigDecimal in order to represent decimal numbers
> >with greater precision than float.
> >
> >If I need to store the (float) number 27.9 in a BigDecimal it
> >transforms into 27.89999999999999857891452847...
> >
> >In tapestry I have my @TextField with translator:number
> >tied to a property "public abstract BigDecimal getAmount();"
> >problem is that tapestry seem to store 27.9 in a float (or maybe
> >double) before storing it in the BigDecimal which mess up the number.
> >:(
> >
> >Now are there a translator for BigDecimal, should I write my own
> >translator or should I re-thing the whole thing?
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


-- 
A bus station is where a bus stops. A train station is where a train stops.
On my desk I have a work station...

Re: stale link when user waits for some time

Posted by Andreas Andreou <an...@di.uoa.gr>.
hari ks wrote:

>hi,
>  Has anyone faced this issue before:
>in multi user environment, when end user waits for
>some time and submits form, it causes stale link.
>

Check out the stateful parameter of Form component.
http://jakarta.apache.org/tapestry/tapestry/ComponentReference/Form.html

> Our
>applicationas specified in one of my previous mail
>uses ognl expressions in html directly to access page
>instance variables without declaring in property
>specification.
>
>thx,
>hari
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>
>---------------------------------------------------------------------
>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


stale link when user waits for some time

Posted by hari ks <ha...@yahoo.com>.
hi,
  Has anyone faced this issue before:
in multi user environment, when end user waits for
some time and submits form, it causes stale link. Our
applicationas specified in one of my previous mail
uses ognl expressions in html directly to access page
instance variables without declaring in property
specification.

thx,
hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Decimal rounding problems when working with currency.

Posted by Paul Ferraro <pm...@columbia.edu>.
The NumberTranslator internally uses java.text.DecimalFormat to 
parse/format numbers.  Unfortunately, DecimalFormat is only capable of 
parsing/formatting numbers with at most double precision or smaller.
To work with BigDecimal (or BigInteger for that matter) you will need to 
write your own Translator implementation.  Contribute your 
implementation to the tapestry.form.translator.Translators configuration 
point and you'll be able to leverage the translator binding prefix.

Paul

Ted Steen wrote:

>Hi all!
>
>I need to work with BigDecimal in order to represent decimal numbers
>with greater precision than float.
>
>If I need to store the (float) number 27.9 in a BigDecimal it
>transforms into 27.89999999999999857891452847...
>
>In tapestry I have my @TextField with translator:number
>tied to a property "public abstract BigDecimal getAmount();"
>problem is that tapestry seem to store 27.9 in a float (or maybe
>double) before storing it in the BigDecimal which mess up the number.
>:(
>
>Now are there a translator for BigDecimal, should I write my own
>translator or should I re-thing the whole thing?
>
>
>  
>


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


RE: Decimal rounding problems when working with currency.

Posted by Patrick Casey <pa...@adelphia.net>.
	You could make it a ValidField and then write your own BigDecimal
validator to do the translation to and from strings, couldn't you?

	--- Pat

> -----Original Message-----
> From: Ted Steen [mailto:ted.steen@gmail.com]
> Sent: Thursday, September 01, 2005 2:40 PM
> To: Tapestry users
> Subject: Decimal rounding problems when working with currency.
> 
> Hi all!
> 
> I need to work with BigDecimal in order to represent decimal numbers
> with greater precision than float.
> 
> If I need to store the (float) number 27.9 in a BigDecimal it
> transforms into 27.89999999999999857891452847...
> 
> In tapestry I have my @TextField with translator:number
> tied to a property "public abstract BigDecimal getAmount();"
> problem is that tapestry seem to store 27.9 in a float (or maybe
> double) before storing it in the BigDecimal which mess up the number.
> :(
> 
> Now are there a translator for BigDecimal, should I write my own
> translator or should I re-thing the whole thing?
> 
> 
> --
> /ted
> 
> ---------------------------------------------------------------------
> 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