OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

ubl-dev message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [Fwd: Re: [ubl-dev] ExchangeRate amounts]


Hello,

you are right this is an important issue, however when
you use BigDecimal for calculations in order to be "more precise" than
float and double, then you need to make sure that you never use a float or
double to initialize the BigDecimal.

You should use the constructor that takes a String:

new BigDecimal("1.5")

instead of

new BigDecimal(1.5)

as this last will generate:
0.1499999999999999944488848768742172978818416595458984375

BigDecimal is good to control the rounding and the error you achieve
should be small...

Let me know if this way your calculation is better.


Regards

Roberto

--
> Roberto Cisternino wrote:
>
>> can you make a sample of rounding errors ?
>>
>> In my country the rounding of amounts has precise rules so it is
>> implicit.
>>
>> I am aware of rounding errors on some big amounts when developers are
>> erroneously using double or float numbers instead of using special
>> numeric
>> types suitable for big numbers (e.g. in Java this is solved using the
>> BigDecimal class)
>
> BigDecimal doesn't solve the rounding problem, which is caused by the
> limitations in which computers process maths.
>
> All BigDecimal buys you is support for numbers which larger numbers of
> decimal places than you get with the fixed width float and double
> formats, and gives you full control over rounding behaviour. What
> BigDecimal cannot do is store the number 1/3 (you need infinite RAM to
> store this number, 0.333...).
>
>> Thanks for any sample of this issue
>
> A simple example:
>
> Customer agrees to settle an GBP300 000 bill by paying EUR400 000. The
> exchange rate is 1.333333... a number that cannot be stored in a
> BigDecimal.
>
> As the exchange rate wants to be limited to 4 decimal places, you end up
> with a rounded off exchange rate of "1.3333".
>
> Because UBL doesn't (yet) have a way to store the target amount, you try
> and calculate it from your exchange rate: GBP300 000 * 1.3333 = EUR399
> 900.
>
> Your target currency amount has a rounding error of EUR100.
>
> If this target currency amount is being used to reconcile against a bank
> statement, the reconciliation will fail. If the target currency amount
> is being used a decrement a statement balance, the balance will show an
> outstanding amount, leading to unnecessary queries.
>
> Regards,
> Graham
> --
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ubl-dev-unsubscribe@lists.oasis-open.org
> For additional commands, e-mail: ubl-dev-help@lists.oasis-open.org
>
>


-- 
* JAVEST by Roberto Cisternino
*
* Document Engineering Services Ltd. - Alliance Member
* UBL Italian Localization SubCommittee (ITLSC), co-Chair
* UBL Online Community editorial board member (ubl.xml.org)
* Italian UBL Advisor

  Roberto Cisternino

  mobile: +39 328 2148123
  skype:  roberto.cisternino.ubl-itlsc

[UBL Technical Committee]
    http://www.oasis-open.org/committees/ubl

[UBL Online Community]
    http://ubl.xml.org

[UBL International Conferences]
    http://www.ublconference.org

[UBL Italian Localization Subcommittee]
    http://www.oasis-open.org/committees/ubl-itlsc

[Iniziativa divulgativa UBL Italia]
    http://www.ubl-italia.org




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]