Interdependent numeric fields

I am using Datatables Editor and have 3 numeric fields which are interdependent:

  1. when I input a numeric data in the first one, the value of the second one must adjust to be equal to the value of the third one (if present) less the value of the first one, multiplied by ten thousand –> 2 = (3-1)*10000
  2. when I input a numeric data in the second one, the value of the third one must adjust to be equal to the value of the first one plus the value of the second one divided by ten thousand –> 3 = 1 +2/10000
  3. when I input a numeric data in the third one, the value of the second one must adjust to be equal to the value of the third one less the value of the first one multiplied by ten thousand –> 2 = (3 -1)/10000

The 3rd part works fine with the following code:

    editor.dependent( 'tms_ft_financialtransaction.RateDeal', function ( val, data, callback ) {
        if (editor.field('tms_ft_financialtransaction.RateSpot').val() ) {
            editor.field('tms_ft_financialtransaction.RateMargin').val((parseFloat(editor.field('tms_ft_financialtransaction.RateDeal').val()) - parseFloat(editor.field('tms_ft_financialtransaction.RateSpot').val()) )*10000);
        }
        callback(true);
    } );

I have 2 problems:

  1. Although 20 is stored in the database, the second field is recalculated when opening the editor and shows decimals
    See example
  2. When I replicate the same code for the second part, I guess due to the first problem, when amending the second field, the third field is recalculated, which recalculates the third, which recalculates the second one, etc.
    Does anybody know how I can fix that?