Propper Way to Format Money

2009-02-25 Thread Daniel Ferreira Castro
I would like an opinion about what is the propper, or more recommended, way
to format a TextField to show money?
Should I declare it TextFieldString or TextFieldFloat?

And to format it with the money symbol ( Like US$) while you type?  Any
ideas?

-- 
Two rules to succeed in life:
1 - don´t tell people everything you know.

We shall go on to the end.
We shall fight in France
We shall fightover the seas and oceans.
We shall fight with growing confidence and growing strength in the air.
We shall defend our island whatever the cost may be
We shall fight on beaches, we shall fight on the landing grounds,
We shall fight in the fields and in the streets,
We shall fight on the hills.
We shall never surrender.
Winston Churchill


Re: Propper Way to Format Money

2009-02-25 Thread Cristiano Kliemann
I wouldn't recomend declaring it as float ou double. With floating point,
sometimes 14.8 minus 13.76 is 1.041.

Use BigDecimal. It is much safer.

-- Cristiano

On Wed, Feb 25, 2009 at 7:20 PM, Daniel Ferreira Castro
dfcas...@gmail.comwrote:

 I would like an opinion about what is the propper, or more recommended, way
 to format a TextField to show money?
 Should I declare it TextFieldString or TextFieldFloat?

 And to format it with the money symbol ( Like US$) while you type?  Any
 ideas?

 --
 Two rules to succeed in life:
 1 - don´t tell people everything you know.
 
 We shall go on to the end.
 We shall fight in France
 We shall fightover the seas and oceans.
 We shall fight with growing confidence and growing strength in the air.
 We shall defend our island whatever the cost may be
 We shall fight on beaches, we shall fight on the landing grounds,
 We shall fight in the fields and in the streets,
 We shall fight on the hills.
 We shall never surrender.
 Winston Churchill



Re: Propper Way to Format Money

2009-02-25 Thread John Krasnay
We keep all our money amounts as ints representing the number of cents.
We have a MoneyField that extends TextField and overrides
getConverter(Class) to return something like this:

public class MoneyConverter implements IConverter {

public Object convertToObject(String value, Locale locale) {
try {
return Math.round(Float.parseFloat(value) * 100);
} catch (NumberFormatException e) {
throw new ConversionException(e)
.setSourceValue(value)
.setResourceKey(MoneyConverter)
}
}

public String convertToString(Object value, Locale locale) {
float amount = ((Number) value).floatValue() / 100;
return String.format(%.2f, amount);
}
}

If you like, you can prepend a dollar sign in convertToString and strip
it in convertToObject.

One thing I want to do but haven't gotten around to is to change the
styling depending on the focus. When the field doesn't have focus it
should be right-aligned, but this is weird when editing, so the idea is
to left-align it while the field has focus.

jk

On Wed, Feb 25, 2009 at 07:20:31PM -0300, Daniel Ferreira Castro wrote:
 I would like an opinion about what is the propper, or more recommended, way
 to format a TextField to show money?
 Should I declare it TextFieldString or TextFieldFloat?
 
 And to format it with the money symbol ( Like US$) while you type?  Any
 ideas?
 
 -- 
 Two rules to succeed in life:
 1 - don´t tell people everything you know.
 
 We shall go on to the end.
 We shall fight in France
 We shall fightover the seas and oceans.
 We shall fight with growing confidence and growing strength in the air.
 We shall defend our island whatever the cost may be
 We shall fight on beaches, we shall fight on the landing grounds,
 We shall fight in the fields and in the streets,
 We shall fight on the hills.
 We shall never surrender.
 Winston Churchill

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org