Search in sources :

Example 1 with FormatterNumber

use of io.vertigo.dynamox.domain.formatter.FormatterNumber in project vertigo by KleeGroup.

the class NumberFormatterTest method testFormatterNumberMLWithDecimal.

/**
 * Test du formatter de nombre.
 * @throws FormatterException e
 */
@Test
public void testFormatterNumberMLWithDecimal() throws FormatterException {
    // séparateur décimal , et accepte .
    // séparateur milliers '\u00A0' => espace insécable + espace (implicite)
    final FormatterNumber formatterNumberLocalized = new FormatterNumberLocalized("#,##0.00|,.|\u00A0 ");
    // BigDecimal
    final BigDecimal pi = new BigDecimal("3.14");
    Assert.assertEquals(pi, formatterNumberLocalized.stringToValue("3.14", DataType.BigDecimal));
    Assert.assertEquals(pi, formatterNumberLocalized.stringToValue("3,14", DataType.BigDecimal));
    Assert.assertEquals(new BigDecimal("0.14"), formatterNumberLocalized.stringToValue("0.14", DataType.BigDecimal));
    Assert.assertEquals("3,14", formatterNumberLocalized.valueToString(pi, DataType.BigDecimal));
    Assert.assertEquals("1" + (char) 160 + "495,00", formatterNumberLocalized.valueToString(1495, DataType.BigDecimal));
    Assert.assertEquals("1\u00A0495,00", formatterNumberLocalized.valueToString(1495, DataType.BigDecimal));
    Assert.assertEquals("1\u00A0495,52", formatterNumberLocalized.valueToString(1495.52, DataType.BigDecimal));
    // Integer
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("1492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("1 492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("1492  ", DataType.Integer));
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("01492  ", DataType.Integer));
    Assert.assertEquals("1\u00A0492,00", formatterNumberLocalized.valueToString(1492, DataType.Integer));
    // Long
    Assert.assertEquals(1492L, formatterNumberLocalized.stringToValue("1492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumberLocalized.stringToValue("1 492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumberLocalized.stringToValue("1492  ", DataType.Long));
    Assert.assertEquals(1492L, formatterNumberLocalized.stringToValue("01492  ", DataType.Long));
    Assert.assertEquals("1\u00A0492,00", formatterNumberLocalized.valueToString(1492L, DataType.Long));
}
Also used : FormatterNumber(io.vertigo.dynamox.domain.formatter.FormatterNumber) FormatterNumberLocalized(io.vertigo.dynamox.domain.formatter.FormatterNumberLocalized) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with FormatterNumber

use of io.vertigo.dynamox.domain.formatter.FormatterNumber in project vertigo by KleeGroup.

the class NumberFormatterTest method testFormatterNumber.

/**
 * Test du formatter de nombre.
 * @throws FormatterException e
 */
@Test
public void testFormatterNumber() throws FormatterException {
    final Formatter formatterNumber = new FormatterNumber("#,###,##0.00");
    // BigDecimal
    final BigDecimal pi = new BigDecimal("3.14");
    Assert.assertEquals(pi, formatterNumber.stringToValue("3.14", DataType.BigDecimal));
    Assert.assertEquals(pi, formatterNumber.stringToValue("3,14", DataType.BigDecimal));
    Assert.assertEquals("3,14", formatterNumber.valueToString(pi, DataType.BigDecimal));
    Assert.assertEquals(new BigDecimal("0.14"), formatterNumber.stringToValue("0.14", DataType.BigDecimal));
    // Integer
    Assert.assertEquals(1492, formatterNumber.stringToValue("1492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumber.stringToValue("1 492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumber.stringToValue("1492  ", DataType.Integer));
    Assert.assertEquals(1492, formatterNumber.stringToValue("01492  ", DataType.Integer));
    // Long
    Assert.assertEquals(1492L, formatterNumber.stringToValue("1492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumber.stringToValue("1 492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumber.stringToValue("1492  ", DataType.Long));
    Assert.assertEquals(1492L, formatterNumber.stringToValue("01492  ", DataType.Long));
    // Double
    Assert.assertEquals(3.14D, formatterNumber.stringToValue("3.14", DataType.Double));
    Assert.assertEquals(3.14D, formatterNumber.stringToValue("3,14", DataType.Double));
    Assert.assertEquals(.14D, formatterNumber.stringToValue("0.14", DataType.Double));
    Assert.assertEquals("3,14", formatterNumber.valueToString(3.14D, DataType.Double));
}
Also used : FormatterNumber(io.vertigo.dynamox.domain.formatter.FormatterNumber) Formatter(io.vertigo.dynamo.domain.metamodel.Formatter) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with FormatterNumber

use of io.vertigo.dynamox.domain.formatter.FormatterNumber in project vertigo by KleeGroup.

the class NumberFormatterTest method testFormatterNumberMLConflit.

/**
 * Test du formatter de nombre.
 * @throws FormatterException e
 */
@Test(expected = IllegalArgumentException.class)
public void testFormatterNumberMLConflit() throws FormatterException {
    final FormatterNumber formatterNumberLocalized = new FormatterNumberLocalized("#,##0.##|.,|.");
    formatterNumberLocalized.stringToValue("3.14", DataType.BigDecimal);
// Détection du conflit entre séparateur décimal et de millier
}
Also used : FormatterNumber(io.vertigo.dynamox.domain.formatter.FormatterNumber) FormatterNumberLocalized(io.vertigo.dynamox.domain.formatter.FormatterNumberLocalized) Test(org.junit.Test)

Example 4 with FormatterNumber

use of io.vertigo.dynamox.domain.formatter.FormatterNumber in project vertigo by KleeGroup.

the class NumberFormatterTest method testFormatterNumberMLNoDecimal.

/**
 * Test du formatter de nombre.
 * @throws FormatterException e
 */
@Test
public void testFormatterNumberMLNoDecimal() throws FormatterException {
    // séparateur décimal . et accepte ,
    // séparateur milliers NO précisé => par défaut sep \u00A0
    final FormatterNumber formatterNumberLocalized = new FormatterNumberLocalized("#,##0.##|.,|");
    // séparateur milliers ' '
    final FormatterNumber formatterNumberLocalizedSpace = new FormatterNumberLocalized("#,##0.##|.,| \u00A0");
    // BigDecimal
    final BigDecimal pi = new BigDecimal("3.14");
    Assert.assertEquals(pi, formatterNumberLocalized.stringToValue("3.14", DataType.BigDecimal));
    Assert.assertEquals(pi, formatterNumberLocalized.stringToValue("3,14", DataType.BigDecimal));
    Assert.assertEquals(new BigDecimal("0.14"), formatterNumberLocalized.stringToValue("0.14", DataType.BigDecimal));
    Assert.assertEquals("3.14", formatterNumberLocalized.valueToString(pi, DataType.BigDecimal));
    Assert.assertEquals("1\u00A0495", formatterNumberLocalized.valueToString(1495, DataType.BigDecimal));
    Assert.assertEquals("1 495.52", formatterNumberLocalizedSpace.valueToString(1495.52, DataType.BigDecimal));
    // Integer
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("1492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("1\u00A0492", DataType.Integer));
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("1492  ", DataType.Integer));
    Assert.assertEquals(1492, formatterNumberLocalized.stringToValue("01492  ", DataType.Integer));
    Assert.assertEquals("1\u00A0492", formatterNumberLocalized.valueToString(1492, DataType.Integer));
    // Long
    Assert.assertEquals(1492L, formatterNumberLocalized.stringToValue("1492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumberLocalizedSpace.stringToValue("1\u00A0492", DataType.Long));
    Assert.assertEquals(1492L, formatterNumberLocalized.stringToValue("1492  ", DataType.Long));
    Assert.assertEquals(1492L, formatterNumberLocalized.stringToValue("01492  ", DataType.Long));
    Assert.assertEquals("1 492", formatterNumberLocalizedSpace.valueToString(1492L, DataType.Long));
}
Also used : FormatterNumber(io.vertigo.dynamox.domain.formatter.FormatterNumber) FormatterNumberLocalized(io.vertigo.dynamox.domain.formatter.FormatterNumberLocalized) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

FormatterNumber (io.vertigo.dynamox.domain.formatter.FormatterNumber)4 Test (org.junit.Test)4 FormatterNumberLocalized (io.vertigo.dynamox.domain.formatter.FormatterNumberLocalized)3 BigDecimal (java.math.BigDecimal)3 Formatter (io.vertigo.dynamo.domain.metamodel.Formatter)1