Example usage for org.apache.wicket.util.convert.converter FloatConverter FloatConverter

List of usage examples for org.apache.wicket.util.convert.converter FloatConverter FloatConverter

Introduction

In this page you can find the example usage for org.apache.wicket.util.convert.converter FloatConverter FloatConverter.

Prototype

FloatConverter

Source Link

Usage

From source file:com.github.zeratul021.wicketnumberconversion.ConvertersTest.java

License:Apache License

/**
 * WICKET-4988 nbsp between digits only/*  w w w  .j a v a2s. c o  m*/
 */
@Test
public void thousandSeperatorWithCurrency() throws Exception {
    FloatConverter fc = new FloatConverter() {
        private static final long serialVersionUID = 1L;

        @Override
        protected NumberFormat newNumberFormat(Locale locale) {
            return NumberFormat.getCurrencyInstance(locale);
        }
    };

    // \u00A0 = nbsp
    // \u00A4 = currency symbol (unspecified currency)
    String string = "1\u00A0234,00 \u00A4";
    System.out.println(Locale.getDefault());
    assertEquals(string, fc.convertToString(Float.valueOf(1234f), Locale.FRENCH));
    assertEquals(Float.valueOf(1234f), fc.convertToObject(string, Locale.FRENCH));
}

From source file:com.github.zeratul021.wicketnumberconversion.ConvertersTest.java

License:Apache License

/**
 * Test float conversions./*from  ww w. j a v  a  2  s .c o m*/
 */
@Test
public void floatConversions() {
    FloatConverter converter = new FloatConverter();
    assertNull(converter.convertToObject("", Locale.US));
    assertEquals(new Float(1.1), converter.convertToObject("1.1", Locale.US));
    assertEquals("1.1", converter.convertToString(new Float(1.1), Locale.US));
    try {
        converter.convertToObject("whatever", Locale.US);
        fail("Conversion should have thrown an exception");
    } catch (ConversionException e) {
        // this is correct
    }
    try {
        converter.convertToObject("1.1whatever", Locale.US);
        fail("Conversion should have thrown an exception");
    } catch (ConversionException e) {
        // this is correct
    }
}

From source file:gr.interamerican.wicket.bo2.markup.html.form.SelfDrawnFloatTextField.java

License:Open Source License

@Override
protected AbstractDecimalConverter<Float> getNumberCoverter() {
    return new FloatConverter();
}