Units 構造体 - システム単位および表示単位へのアクセス

Units 構造体は、システム単位のスケール、タイプ、および表示単位を取得および設定するためのシステム グローバル変数および特定のメソッドへのアクセスを提供します。

システム グローバル:

units.DisplayType

現在の単位表示タイプを <name> で取得/設定します。

有効な単位表示タイプは次のとおりです。

#Generic #Metric #US #custom
units.MetricType

現在のメートル単位の表示タイプを <name> で取得/設定します。

有効なメートル単位の表示タイプは次のとおりです。

#Millimeters #Centimeters #Meters #Kilometers
units.USType

現在の US 標準単位の表示タイプを <name> で取得/設定します。

有効な US 標準単位の表示タイプは次のとおりです。

#Frac_In #Dec_In #Frac_Ft #Dec_Ft #Ft_Frac_In #Ft_Dec_In
units.USFrac

現在の US 分数の表示タイプを <name> で取得/設定します。

有効な US 分数の表示タイプは次のとおりです。

#Frac_1_1 #Frac_1_2 #Frac_1_4 #Frac_1_8 #Frac_1_10 #Frac_1_16 #Frac_1_32 #Frac_1_64 #Frac_1_100
units.CustomName

現在のカスタム単位名を <string> で取得/設定します。

units.CustomValue

現在のカスタム単位値を <float> で取得/設定します。

units.CustomUnit

現在のカスタム単位タイプを <name> で取得/設定します。

有効なカスタム単位の表示タイプは次のとおりです。

#Inches #Feet #Miles #Millimeters #Centimeters #Meters #Kilometers
units.SystemScale

現在のシステム単位スケールの値を <float> で取得/設定します。

これは、[カスタマイズ](Customize Units Setup) > [システム単位設定](System Units Setup) > [システム単位スケール](System Units Scale)領域に表示される値です。

units.SystemType

現在のシステム単位スケールのタイプを <name> で取得/設定します。

これは、[カスタマイズ] (Customize) > [単位設定](Units Setup) > [システム単位設定](System Units Setup) > [システム単位スケール](System Units Scale)領域に表示される単位です。

有効なシステム単位のタイプは次のとおりです。

#Inches #Feet #Miles #Millimeters #Centimeters #Meters #Kilometers

メソッド:

units.formatValue <float>

現在の単位スケールの <float> を表す <string> 値を返します。

このメソッドでは、文字列オーバーフローが発生する可能性があります(特に単位がマイルまたはキロメートルに設定されている場合)。

オーバーフローが発生すると、ランタイム エラーが生成されます。

例:

    units.DisplayType = #Generic
    -->#Generic
    units.SystemType = #inches
    -->#inches
    units.formatValue 123.45
    -->"123.45"
    units.DisplayType = #Metric
    -->#metric
    units.MetricType = #meters
    -->#meters
    units.formatValue 123.45
    -->"3.136m"
    units.MetricType = #centimeters
    -->#centimeters
    units.formatValue 123.45
    -->"313.563cm"
    units.DisplayType = #US
    -->#us
    units.USType = #ft_Frac_In
    -->#ft_Frac_In
    units.formatValue 123.45
    -->"10'3 14/32""
    units.USType = #Dec_Ft
    -->#dec_Ft
    units.formatValue 123.45
    -->"10.287'"
    units.DisplayType = #Custom
    --#custom
    units.formatValue 123.45
    -->"0.016FL"
units.decodeValue <string>

現在の単位設定を使用して <string> を解析し、<float> を返します。

文字列の解析中にエラーが発生すると、ランタイム エラーが生成されます。

これは、上記で説明した units.formatValue() の逆関数です。

値の後方および前方変換は、概数エラーによる精度低下を招きます。

例:

    units.DisplayType = #Generic
    -->#Generic
    units.decodeValue "3.136m"
    -->123.465
    units.decodeValue "313.563cm"
    -->123.45
    units.decodeValue "10'3 14/32\""
    -->123.438
    units.decodeValue "10.287'"
    -->123.444
    units.decodeValue "0.016FL"
    -->126.72