0

Wasn't sure how to better describe the problem in the title, but basically I have a beanio XML where one of the fields is this:

<field name="number" length="19" padding="0" justify="right"/>

My issue is that the value that goes here can be negative or positive, but I need the positive or negative sign to be at the front while the number itself is in the back.

For example, I am currently getting:

0000000000000-10500

However, what I need is:

-000000000000010500 

Is there a way to edit the field so that it comes out with the negative/positive sign in front?

Abra
  • 19,142
  • 7
  • 29
  • 41
Cris Manrique
  • 83
  • 1
  • 7

1 Answers1

1

Disclaimer: This is not tested

You can try:

<field name="number" length="19" padding="0" justify="right" format="-#0"/>

OR

<field name="number" length="19" padding="0" justify="right" format="#0;-#0"/>

OR if that fails:

<field name="number" length="19" padding="0" justify="right" format="##################0;-##################0"/>

18 x '#' and 1 x '0'

OR

<field name="number" length="19" padding="0" justify="right" format="0000000000000000000;-0000000000000000000"/>

19 x '0'.

See the Reference Guide and just google how to use the decimal format pattern for the java.lang.Number field - DecimalFormat API

nicoschl
  • 2,346
  • 1
  • 17
  • 17
  • I got it working with the last example you showed. Would you know how to do the same thing if the number was a String data type? Currently trying to research how online but haven't seen anything relevant. – Cris Manrique Aug 11 '22 at 23:29
  • @CrisManrique it should actually be a new question, although related. You could do it with a custom `TypeHandler` that does the formatting. – nicoschl Aug 12 '22 at 00:20