Displaying decimal places using a TextFieldFloat
I use a TextFieldFloat as shown below. Since this field represents a currency unit (in this case, pound sterling) I want to have two decimal places shown always. For example: 0.00 5.00 6.10 3.28. What I find when I run my web application is that, after form submission, the model's Float value is always shown without any trailing zeroes in the decimals. To use the same examples again, I get: 0 5 6.1 3.28. Is there anything simple I can do to get my component to display two decimal places always? (Failing this, I intend to work around my problem by changing the TextFieldFloat to a TextField with a String for its model, and converting this String to a Float value myself after form submission.) HTML mark-up lt;input type=text wicket:id=flPriceInPounds size=10/gt; Java code (within a WebPage) Form frmForm = new Form(frmForm) { [...] }; frmForm.setModel(new CompoundPropertyModel([...])); add(frmForm); TextFieldFloat txtMriceInPounds = new TextFieldFloat(flPriceInPounds, Float.class); frmForm.add(txtPriceInPounds); Java code: declaration within the form's compound property model public Float flPriceInPounds = null; Regards, Ian Marshall -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Displaying-decimal-places-using-a-TextField-Float-tp3074547p3074547.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Displaying decimal places using a TextFieldFloat
you can keep the field as float and give it its own converter that always shows two decimal places -igor On Mon, Dec 6, 2010 at 4:38 PM, Ian Marshall ianmarshall...@gmail.com wrote: I use a TextFieldFloat as shown below. Since this field represents a currency unit (in this case, pound sterling) I want to have two decimal places shown always. For example: 0.00 5.00 6.10 3.28. What I find when I run my web application is that, after form submission, the model's Float value is always shown without any trailing zeroes in the decimals. To use the same examples again, I get: 0 5 6.1 3.28. Is there anything simple I can do to get my component to display two decimal places always? (Failing this, I intend to work around my problem by changing the TextFieldFloat to a TextField with a String for its model, and converting this String to a Float value myself after form submission.) HTML mark-up lt;input type=text wicket:id=flPriceInPounds size=10/gt; Java code (within a WebPage) Form frmForm = new Form(frmForm) { [...] }; frmForm.setModel(new CompoundPropertyModel([...])); add(frmForm); TextFieldFloat txtMriceInPounds = new TextFieldFloat(flPriceInPounds, Float.class); frmForm.add(txtPriceInPounds); Java code: declaration within the form's compound property model public Float flPriceInPounds = null; Regards, Ian Marshall -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Displaying-decimal-places-using-a-TextField-Float-tp3074547p3074547.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Displaying decimal places using a TextFieldFloat
Hi Ian, you can provide an BigDecimalConverter that works with an NumberFormat with its minimumFractionDigits setted to 2 On Mon, Dec 6, 2010 at 12:38 PM, Ian Marshall ianmarshall...@gmail.comwrote: I use a TextFieldFloat as shown below. Since this field represents a currency unit (in this case, pound sterling) I want to have two decimal places shown always. For example: 0.00 5.00 6.10 3.28. What I find when I run my web application is that, after form submission, the model's Float value is always shown without any trailing zeroes in the decimals. To use the same examples again, I get: 0 5 6.1 3.28. Is there anything simple I can do to get my component to display two decimal places always? (Failing this, I intend to work around my problem by changing the TextFieldFloat to a TextField with a String for its model, and converting this String to a Float value myself after form submission.) HTML mark-up lt;input type=text wicket:id=flPriceInPounds size=10/gt; Java code (within a WebPage) Form frmForm = new Form(frmForm) { [...] }; frmForm.setModel(new CompoundPropertyModel([...])); add(frmForm); TextFieldFloat txtMriceInPounds = new TextFieldFloat(flPriceInPounds, Float.class); frmForm.add(txtPriceInPounds); Java code: declaration within the form's compound property model public Float flPriceInPounds = null; Regards, Ian Marshall -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Displaying-decimal-places-using-a-TextField-Float-tp3074547p3074547.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Pedro Henrique Oliveira dos Santos
Re: Displaying decimal places using a TextFieldFloat
Thanks Igor and Pedro. I'll do that. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Displaying-decimal-places-using-a-TextField-Float-tp3074547p3074627.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org