Numerical types are not my speciality yet. Can anybody help me make this simple division work?
'Primary Container Weight Purchased Colli': number positive '10^-3 kg' =
switch ^ >'Colli Type'>'Colli Type' (
| node as $ =>
switch $.'Secondary Packaging' (
| 'Yes' as $ => $ >'Primary Container Weight'.'Net Weight'
| 'No' as $ => $ >'Primary Container Weight'.'Net Weight'
)
| none => 1000
)
'Primary Container Weight Sold Colli': number positive '10^-3 kg' =
switch ^ ^ ^ ^ >'Colli Type'>'Colli Type' (
| node as $ =>
switch $.'Secondary Packaging' (
| 'Yes' as $ => $ >'Primary Container Weight'.'Net Weight'
| 'No' as $ => $ >'Primary Container Weight'.'Net Weight'
)
| none => 1000
)
'Factor': number '10^-3 factor' =
division (
product (
.'Primary Container Weight Purchased Colli',
1000
) as '10^-6 kg',
.'Primary Container Weight Sold Colli'
)
numerical-types
'10^-3 factor'
= '10^-6 kg' / '10^-3 kg'
= '10^-3 colli' / 'colli'
= '10^-6 factor' / '10^-3 factor'
= 'percent' * 1 * 10 ^ 1
= '10^-2 percent' * 1 * 10 ^ -1
// = '10^-6 factor' * 1 * 10 ^ -3
@numerical-type: (
label: ""
decimals: 3
)
'10^-6 kg'
= '10^-3 kg' * 1 * 10 ^ 3
Arithmetic operators like product and division can not be nested currently. An additional property is required.
This should work:
root {
'Primary Container Weight Purchased Colli': number positive '10^-3 kg'
'Primary Container Weight Sold Colli': number positive '10^-3 kg'
'Intermediate': number '10^-6 kg' = product ( 1000 as '10^-3 factor', .'Primary Container Weight Purchased Colli' ) @hidden
'Factor': number '10^-3 factor' = division ( .'Intermediate' as '10^-6 kg', .'Primary Container Weight Sold Colli' )
}
numerical-types
'10^-3 kg'
@numerical-type: (
label: "Kg"
decimals: 3
)
'10^-3 factor'
= '10^-6 kg' / '10^-3 kg'
@numerical-type: (
label: ""
decimals: 3
)
'10^-6 kg'
= '10^-3 factor' * '10^-3 kg'
1 Like
The idea is to give intermediate results a name and place in the user interface as well, for understandability and to prevent duplication.
1 Like
'Collo Sales Price': number '10^-3 euro/collo' = sum ( .'Net Sales Price', .'Commission Costs' )
'Collo Net Weight': number '10^-3 kg/collo' = ^ >'Week Price'>'Colli Type'>'Colli Type'.'Net Weight'
'Sales Price Kg': number '10^-3 euro/Kg' = division ( .'Collo Sales Price' as '10^-3 euro/collo', .'Collo Net Weight' )
‘conversion rule’ 10^-3 euro/collo was not found in ‘division conversions’. None exist.
application.alan(31344, 17): defined by .‘10^-3 euro/Kg’ of type ‘application’.‘numerical types’.‘type’?‘quantity’
In the case above, how can I make it work? Thanks in advance 
Ok, 1 euro/collo and a net weight of 1 kg/collo should lead to 1 euro / kg, right?
Under ‘the hood’, the numbers in that case are: 1000, 1000 and 1000 (so all with three decimals)
The calculation you want to perform is: 1000 / 1000, which would lead to an output of 1, which would show up as 0,001 euro/kg.
So, the calculation should be 1000000 / 1000, so you want the first number to be in ‘10^-6 euro/collo’
the calculation should be:
'Sales Price Kg': number '10^-3 euro/Kg' = division ( from '10^-3 euro/collo' .'Collo Sales Price' as '10^-6 euro/collo', .'Collo Net Weight' )
And in the numerical type system, you need this:
'10^-3 euro/collo'
'10^-6 euro/collo'
= '10^-3 euro/collo' * 1 * 10 ^ 3
'10^-3 kg/collo'
'10^-3 euro/Kg'
= '10^-6 euro/collo' / '10^-3 kg/collo'
1 Like
Thank you Rick. This really helps to intuitively understand the numeric rules better 
Ok, good to hear! We are planning to make working with decimals a bit easier, but the basic idea would stay more or less the same.
I am encountering the following error on = '10^-6 euro/collo' / '10^-3 kg/collo':
expected a integer literal (to set ‘factor’) but saw key literal '10^-3 kg/collo'
'10^-3 kg/collo'
= '10^-3 kg' * 'primary/secondary'
= 'gram/pallet' / 'colli/pallet'
//= 'gram' * 1 * 10 ^ 0
= '10^-1 gram' / 1 * 10 ^ 1
= '10^-3 kg' * 1 * 10 ^ 0
@numerical-type: (
label: "Kg/collo"
decimals: 3
)
'10^-3 euro/Kg'
= '€cent/Kg' * 1 * 10 ^ 1
= '10^-6 euro/collo' / '10^-3 kg/collo'
@numerical-type: (
label: "€/Kg"
decimals: 3
)
Ah, yeah, there is a specific order required there:
- multiplication ( = ‘a’ * ‘b’ )
- divisions ( = ‘a’ / ‘b’ )
- unit conversions ( = ‘b’ * c * 10 ^ d )
The order is reversed in the list of conversions for ‘10^-3 euro/Kg’
1 Like