Revit .NET has provided the Units API since version 2014. In this series of posts, we explore the Revit Units .NET API a bit and provide sample code and analysis as usual.
To display an amount nicely, a decimal separator is necessary and it is better to group the digits as well. In English, the dot (period) is used as the decimal separator, the comma as the digit grouping separator, and three digits are in each group. For example, 1,234,567.89 is a nice expression. In some other countries or cultures, different combinations of decimal separator, digit group separator and digit group number will be used, e.g. in Italy, 1.234.567,89.
In this post, let’s figure all combinations of decimal separator, digit group separator and digit group number that Revit supports.
public static void FigureGoodCombinationsOfDecimalSymbolAndDigitGroupingSymbolNumber()
{
using (StreamWriter sw = new StreamWriter(@"c:\temp\RevitGoodCombinationsOfDecimalSymbolAndDigitGroupingSymbolNumber.txt"))
{
sw.WriteLine("Combinations Of Decimal Symbol And Digit Grouping Symbol/Number");
sw.WriteLine("Decimal Symbol, Digit Grouping Symbol, Digit Grouping Number");
foreach (DecimalSymbol ds in Enum.GetValues(typeof(DecimalSymbol)))
{
foreach (DigitGroupingSymbol dgs in Enum.GetValues(typeof(DigitGroupingSymbol)))
{
foreach (DigitGroupingAmount dga in Enum.GetValues(typeof(DigitGroupingAmount)))
{
if (Units.IsValidDecimalSymbolAndGrouping(ds, dgs, dga))
{
sw.WriteLine("{0}\t{1}\t{2}", ds, dgs, dga);
}
}
}
}
}
}
…
RevitUnitsAPI.FigureGoodCombinationsOfDecimalSymbolAndDigitGroupingSymbolNumber();
…
The output may look something like the following:
Combinations Of Decimal Symbol And Digit Grouping Symbol/Number
Decimal Symbol, Digit Grouping Symbol, Digit Grouping Number
Dot Dot Two
Dot Dot Three
Dot Comma Two
Dot Comma Three
Dot Space Two
Dot Space Three
Dot Apostrophe Two
Dot Apostrophe Three
Dot Apostrophe Two
Dot Apostrophe Three
Comma Dot Two
Comma Dot Three
Comma Comma Two
Comma Comma Three
Comma Space Two
Comma Space Three
Comma Apostrophe Two
Comma Apostrophe Three
Comma Apostrophe Two
Comma Apostrophe Three
It is surprising to see that Dot can serve as both decimal separator and digit group separator at the same time, so does the Comma! Are these combinations really valid? Does anywhere in the world express numbers this way?
1,234,567,89
1.234.567.89
If so, it’s confusing, isn’t it? We can kind of figure what fractional digits (e.g. the 89 here) are in the expressions supposing only two are there, but what about there are three fractional digits?
As can also be seen, Revit does not support the apostrophe (’) being as decimal separator though it is really used somewhere in the world. In addition, in some cultures, the digit grouping number may be four to be meaningful!
Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.