On 11/10/2010 10:00 AM, Thilo Götz wrote: > On 11/10/2010 15:40, Frank Schilder wrote: >> Hi all, >> >> I'm trying to represent the value of a money amount as BigDecimal. For >> example $3.25 should be annotated with a Money annotation. The Money >> annotation should have a feature called val and the value of this feature >> should be of type BigDecimal instead of float (or double). >> >> It has been suggested elsewhere that using floating point numbers is not a >> good idea for representing money amounts: >> http://www.ibm.com/developerworks/java/library/j-jtp0114/ >> >> Unfortunately, BigDecimals are not supported as CAS type for the value of an >> annotation feature. Would it be possible to add this type easily or could >> you suggest a work-around? > It is not easy to add this type. > > The easiest work-around would be to put a string representation > in the CAS. Just use the BigDecimal.toString() method to encode, > and the BigDecimal(String) constructor to decode. I know it's > ugly. If you hide this conversion behind some accessor methods > for your money annotation, you can later change this implementation > for something better.
If you use the JCas approach, you can put the "hiding" conversions into some customized methods in the JCas cover type. -Marshall > A more efficient representation would be to build your own CAS > datatype with an int for the scale and a byte array for the > value. However, that seems like a lot of work for little benefit. > But then I don't know what your application is. > > HTH, > Thilo > >> Thanks a lot, >> Frank >> >
