🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
MetricImperial
This page was created by Hans.karlsen on 2025-09-03. Last edited by Wikiadmin on 2026-07-29.

You can store measurements in metric units while letting each user view and edit supported values in metric or imperial units; this page is for MDriven Designer modelers configuring that behavior.

How Metric/Imperial conversion works

Metric/Imperial support keeps the stored value in the metric unit. MDriven converts the value for display and converts edited input back to the metric value for storage when the user has selected imperial units.

For example, configure a temperature attribute with CelsiusFahrenheit. A stored metric value is treated as Celsius. When the user's temperature setting selects imperial units, the UI presents the value in Fahrenheit; when the user edits that Fahrenheit value, MDriven converts it back to Celsius before storing it.

The feature is controlled by the SysCultureSettingsSingleton pattern in the SysTranslations merge model described in Documentation:Localization. It is a presentation and editing feature; it does not change the metric unit used by the model value.

Configure a converted attribute

To enable conversion, add the MetricImperial tagged value to an attribute.

  1. Select the attribute in MDriven Designer.
  2. Ensure that its type is decimal, float, double, or int.
  3. Add the MetricImperial tagged value.
  4. Set its value to the conversion pair that represents the metric unit stored by the attribute and the imperial unit to present.
  5. Optionally add MetricImperialUIDecimals when this attribute needs a specific number of displayed decimal places.
  6. Configure the matching SysCultureSettingsSingleton.MetricNotImperial_... setting, as described below.

For example, for an attribute named Length that stores millimetres, set MetricImperial=MillimeterInch. If the user selects imperial length units, the UI shows inches and accepts inches as input; the attribute continues to store millimetres.

Supported conversion values

MetricImperial value Measurement category Metric value stored Imperial value presented when selected
GramOunce Weight Gram Ounce
MillimeterInch Length Millimetre Inch
MilliliterFluidOunce Volume Millilitre Fluid ounce
CelsiusFahrenheit Temperature Celsius Fahrenheit
SquareKilometersSquareMiles Area Square kilometre Square mile
SquareMetersSquareFeet Area Square metre Square foot
SquareCentimetersSquareInches Area Square centimetre Square inch
KilometersPerHourMilesPerHour Velocity Kilometres per hour Miles per hour
MetersPerSecondFeetPerSecond Velocity Metres per second Feet per second

Choose the conversion value that matches the unit in which the attribute is stored. Do not use this feature to convert between two non-metric stored units.

Control the user's unit preference

SysCultureSettingsSingleton provides one Boolean setting per measurement category. A value of true means metric; a value of false means imperial.

Setting Controls conversion values
MetricNotImperial_Area SquareKilometersSquareMiles, SquareMetersSquareFeet, and SquareCentimetersSquareInches
MetricNotImperial_Length MillimeterInch
MetricNotImperial_Temperature CelsiusFahrenheit
MetricNotImperial_Velocity KilometersPerHourMilesPerHour and MetersPerSecondFeetPerSecond
MetricNotImperial_Volume MilliliterFluidOunce
MetricNotImperial_Weight GramOunce

The settings default to true, so the default presentation is metric. You can make these properties derived and let each user own the values used by the derivation. This lets one user work in metric units while another user works in imperial units without changing the metric values stored in the model.

For example, derive MetricNotImperial_Weight from a preference owned by the current user. A user whose preference evaluates to false sees attributes tagged GramOunce as ounces; a user whose preference evaluates to true sees the same values as grams.

Set display precision

Use the optional MetricImperialUIDecimals tagged value to set the number of decimal places after conversion for one attribute. Its value must be an integer.

For example, add MetricImperialUIDecimals=3 to a MillimeterInch attribute when its inch presentation must show three decimal places.

If you do not set MetricImperialUIDecimals, MDriven uses twice SysCultureSettingsSingleton.DefaultDecimalDisplay. DefaultDecimalDisplay defaults to 2 when it is not set, so the resulting default for a converted imperial value is four decimal places. The additional precision helps compensate for the lower granularity of imperial units.

DefaultDecimalDisplay also supplies a default decimal string format for Angular, Blazor, and WPF when no format is already present. Configure model-level precision and scale separately; see Documentation:Precision.

PresentationUnit labels

Metric/Imperial conversion updates the attribute's PresentationUnit according to the active MetricNotImperial setting. Use the PresentationUnit to make the current unit clear in the UI.

For example, a label written as:

The temp (°C)

is presented as:

The temp (°F)

when MetricNotImperial_Temperature=false.

This behavior is tied to the conversion category. Ensure that the attribute's conversion tag and its PresentationUnit describe the same measurement.

Configuration checklist

  • Keep the attribute value in the metric unit named first by its MetricImperial value.
  • Add MetricImperial only to supported numeric attribute types: decimal, float, double, or int.
  • Select the conversion pair that matches the stored metric unit.
  • Set the matching MetricNotImperial preference to true for metric or false for imperial.
  • Use MetricImperialUIDecimals only where the default converted-value precision is not appropriate.
  • Keep PresentationUnit text consistent with the selected conversion pair.

See also