Operating on ExactDimension

#1

If I have two fields of type ExactDimension and I want to combine them in a Metric or a stored calc, how does the engine arrive at the final ExactDimension.unit (or MonetaryValue.currency)?

For example, is the following data model valid such that the ‘cost’ field will be computed? Also, lets say that the volume has unit = ‘Liter’ and the gasStation.fuelPrice has unit ‘$/gallon’, will the engine accurately compute the a monetaryValue?

entity type ReFuel schema name ‘RFUEL’ {
gasStation : GasStation
volume : ExactDimension
cost : MonetaryValue stored calc “volume * gasStation.fuelPrice”
}

entity type GasStation extends Building type key ‘GSSTA’ {
fuelPrice : ExactDimension
}

0 Likes

#2

Unit Conversion will happen automatically to a common unit. You can observe the definitions of units by looking at Unit objects in the database with Unit.fetch().

To specify the unit in which you’d like the data to be stored, you can use the “convertToUnit” expression engine function e.g.

entity type ReFuel schema name 'RFUEL' {
    cost : MonetaryValue stored calc "convertToUnit('usd', volume * gasStation.fuelPrice)"
}
0 Likes