You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by David van Coevorden <da...@gmail.com> on 2004/11/02 16:02:43 UTC

Number formatting

Hi 

How could I limit the number of decimals of numbers in my forms?
Instead of having 23.35342342 etc. I want to display 23.35 .
I considered using javascript but I don't know how it combines with my tapestry
components. Any simple solutions/examples?

Thanks
David



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


Re: Number formatting

Posted by David van Coevorden <da...@gmail.com>.
Thank you!


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


Re: Number formatting

Posted by James Sherwood <js...@romulin.com>.
Oh you just want a component for numbers.

I have never used it, but there is a NumericField component in the contrib
which does number formating I beleive, and if it doesnt, it should be easy
to copy and modify.

Its org.apache.tapestry.contrib.valid.NumericField

James.

Simply copy the TextField component
----- Original Message ----- 
From: "David van Coevorden" <da...@gmail.com>
To: <ta...@jakarta.apache.org>
Sent: Tuesday, November 02, 2004 11:52 AM
Subject: Re: Number formatting


> James,
> Thank you. I know this in fact, sorry for not being clear about that. My
concern
> is that I do not want my business objects to be cluttered with formatting
logic.
> The logical place for formatting would be in the tapestry layer. Of course
I can
> create a method (in the tapestry page class) that wraps each property that
I
> want formatted, but that is very verbose. So I would like see a tapestry
> component that does this for me. Maybe it is really easy to implement, but
I'm
> not fluent enough in tapestry yet to do it and hoped to see an example...
>
> Cheers David
>
>
>
> ---------------------------------------------------------------------
> 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: Number formatting

Posted by David van Coevorden <da...@gmail.com>.
James,
Thank you. I know this in fact, sorry for not being clear about that. My concern
is that I do not want my business objects to be cluttered with formatting logic.
The logical place for formatting would be in the tapestry layer. Of course I can
create a method (in the tapestry page class) that wraps each property that I
want formatted, but that is very verbose. So I would like see a tapestry
component that does this for me. Maybe it is really easy to implement, but I'm
not fluent enough in tapestry yet to do it and hoped to see an example...

Cheers David



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


Re: Number formatting

Posted by James Sherwood <js...@romulin.com>.
You can do it through java this way:

double d = 1.3454234;
  DecimalFormat df = (DecimalFormat)DecimalFormat.getNumberInstance();
  df.applyPattern("#,###.00");
  System.out.println(df.format(d));

Just put the df.format() in your gets and sets for the variable you are
using in the form so it always formats the value on the way through.  You
might want to check to make sure its a number first tho ;)

Oh and create the df statically so it only ever creates it the once.

James

----- Original Message ----- 
From: "David van Coevorden" <da...@gmail.com>
To: <ta...@jakarta.apache.org>
Sent: Tuesday, November 02, 2004 11:02 AM
Subject: Number formatting


> Hi
>
> How could I limit the number of decimals of numbers in my forms?
> Instead of having 23.35342342 etc. I want to display 23.35 .
> I considered using javascript but I don't know how it combines with my
tapestry
> components. Any simple solutions/examples?
>
> Thanks
> David
>
>
>
> ---------------------------------------------------------------------
> 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