コード
// 数値のみの変換
UnitNumberConverter numberconverter = new UnitNumberConverter(UnitNumberConverter.Word.def);
Console.WriteLine("億千万={0}",
numberconverter.GetValue("億千万"));
// 長さ用のUnitNumberConverter
LengthConverter lengthconverter = new LengthConverter();
Console.WriteLine("42.195kmをメートルで表すと {0}",
lengthconverter.Convert("42.195km", "メートル"));
// 時間用のUnitNumberConverter
TimeConverter timeconverter = new TimeConverter();
Console.WriteLine("5.5週間を分で表すと {0}",
timeconverter.Convert("5.5週間", "分"));
// ユーザー定義のUnitNumberConverter(角度)
UnitNumberConverter userunitconverter = new UnitNumberConverter(
UnitNumberConverter.Word.def,
new UnitNumberConverter.Word[]{
new UnitNumberConverter.Word(
"度",
UnitNumberConverter.Word.Meaning.Unit,
1.0),
new UnitNumberConverter.Word(
"分",
UnitNumberConverter.Word.Meaning.Unit,
1.0 / 60.0),
new UnitNumberConverter.Word(
"秒",
UnitNumberConverter.Word.Meaning.Unit,
1.0 / 60.0 / 60.0),
new UnitNumberConverter.Word(
"°",
UnitNumberConverter.Word.Meaning.Unit,
1.0),
new UnitNumberConverter.Word(
"'",
UnitNumberConverter.Word.Meaning.Unit,
1.0 / 60.0),
new UnitNumberConverter.Word(
"\"",
UnitNumberConverter.Word.Meaning.Unit,
1.0 / 60.0 / 60.0),
new UnitNumberConverter.Word(
"グラード",
UnitNumberConverter.Word.Meaning.Unit,
0.9),
new UnitNumberConverter.Word(
"grad",
UnitNumberConverter.Word.Meaning.Unit,
0.9),
new UnitNumberConverter.Word(
"ラジアン",
UnitNumberConverter.Word.Meaning.Unit,
180.0 / Math.PI),
new UnitNumberConverter.Word(
"rad",
UnitNumberConverter.Word.Meaning.Unit,
180.0 / Math.PI),
});
Console.WriteLine("3radをgradで表すと {0}",
userunitconverter.Convert("3rad", "grad"));
結果
億千万=110000000
42.195kmをメートルで表すと 42195
5.5週間を分で表すと 55440
3radをgradで表すと 190.985931710274