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

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

Introduction

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

Prototype

@Override
public Float convertToObject(final String value, final Locale locale) 

Source Link

Usage

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

License:Apache License

/**
 * WICKET-4988 nbsp between digits only//from w w w. ja v  a2s .  com
 */
@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   w  ww. j ava  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
    }
}