Back to Devexpress

How to: Convert Between Metric Prefixes

officefileapi-15423-unit-conversion-api-examples-how-to-convert-between-metric-prefixes.md

latest1.7 KB
Original Source

How to: Convert Between Metric Prefixes

  • Sep 19, 2023

The Unit Conversion API includes a special converter that helps you convert between different metric prefixes. The following code illustrates how to display a pressure that is equal to 760 millimeters of mercury in hectopascals.

csharp
using DevExpress.UnitConversion;
using System.Diagnostics;
            // The pressure value is set to 760 mmHg.
            QuantityValue<Pressure> pressure = (760).MmHg();
            // Since it is a quantity value, it should be transformed to a proper measurement unit
            // to obtain a value for display or for comparison.
            // The pressure is obtained in Pascals and then converted into hectoPascals.
            MetricUnitsConverter prefixConverter = new MetricUnitsConverter();
            double pressure_in_hPa = prefixConverter.Convert(pressure.ToPascals(), MetricPrefix.None, MetricPrefix.Hecto);
            Debug.WriteLine(pressure_in_hPa);
vb
Imports DevExpress.UnitConversion
Imports System.Diagnostics
            ' The pressure value is set to 760 mmHg.
            Dim pressure As QuantityValue(Of Pressure) = (760).MmHg()
            ' Since it is a quantity value, it should be transformed to a proper measurement unit
            ' to obtain a value for display or for comparison.
            ' The pressure is obtained in Pascals and then converted into hectoPascals.
            Dim prefixConverter As New MetricUnitsConverter()
            Dim pressure_in_hPa As Double = prefixConverter.Convert(pressure.ToPascals(), MetricPrefix.None, MetricPrefix.Hecto)
            Debug.WriteLine(pressure_in_hPa)