Calculated numbers using javascript not displayed correctly in interactive report

333 views Asked by At

I am pretty new to oracle apex and working on a case for myself to get oracle apex 5 more in control... :-).... hopefully. I have 2 pages: 1 interactive report on a table and 1 for a form to add and modify records. In the form there are 4 fields: P12_VAT_PERC, P12_VAT_AMOUNT, P12_NET_AMOUNT and P12_TOT_AMOUNT (all 4 database fields, type number). I have created one dynamic action on event lose focus on one of the 4 field items mentioned above. The event is fired when true with 2 actions. Action 1 is set value on P12_VAT_AMOUNT, set type javascript expression:

($v('P12_VAT_PERC') / 100) * $v('P12_NET_AMOUNT');

Action 2 set value on P12_TOT_AMOUNT, set type javascript expression:

parseFloat($v('P12_NET_AMOUNT'))+parseFloat(($v('P12_VAT_PERC') / 100) * $v('P12_NET_AMOUNT'));

In the form it works. Values for P12_VAT_AMOUNT and P12_TOT_AMOUNT are calculated and displayed correctly as number (with the decimals if applicable) once calculated after losing focus on one of the 4 fields. But when page is submitted the value is not displayed correctly in the report and also not correct stored in database. I.e. before submitting P12_VAT_AMOUNT is calculated and displayed as 25.919999999999998. After submitting in the report it is displayed as 25919999999999998. I am missing the decimal sign. Also in the database it is stored like 2.592E16.

When I open this record in the form again for editing, it is initially displayed as in the report like 25919999999999998. When changing i.e. P12_VAT_PERC and change the focus, the field is caclulated correctly and displayed again with decimal sign on correct place. After submit it goes wrong again. To solve this, I found out that having the dynamic action also fired on page load (I enabled this option), this part of the problem was solved. Values are displayed correctly in form by javascript, but the wrong value seems to be stored in the database and not correctly displayed in the interactive report.

Same behavior for P12_TOT_AMOUNT.

I have the idea that APEX is using the dot as decimal character but the regional settings (Dutch) of the machine on which the browser is running are set to comma. When I enter a comma as decimal sign, the calculated fields are showing as NaN.

What do i do wrong? Hope someone can help me and put me in de direction where to find the solution.

1

There are 1 answers

0
juseit On BEST ANSWER

The real problem that javascript is using always a dot as decimal separator and my locale is set to decimal. I will now focus on that problem. It has nothing to do with Apex.