I’m developing some code to present currency symbols as part of a label on my application, and I have a reference list of currency symbols in Unicode hex format. In my code I am formatting the currency as follows:
(currency symbol) (decimal string) (currency description)
This approach works fine for most of the symbols, however I notice that some of the symbols are automatically shifted to the right of the decimal value even when explicitly placed to the left. Using the debugger, I see this behavior even at the most fundamental level in the strings themselves, so this is not a case of any manipulation at higher levels by the rendering in the presentation layer. The following code presents the simple case demonstrating the problem:
string rialSymbol = "\ufdfc";
string amount = "123.45";
string description = "Rials";
string plainConcat = rialSymbol + " " + amount + " " + description;
Debug.WriteLine(plainConcat);
The debug output (which matches also what’s seen in the application UI) is as follows:
123.45 (rial symbol) Rials
(Note: symbol is to the right of the decimal not the left, as specified)
I have tried many approaches and varieties of string formatting, culture formatting etc., but nothing seems to address this issue. How can I enforce the placement of the unicode character without having the framework decide upon the symbol placement relative to the decimal value? This works with most other characters, why does the Rial (and a few others) cause this type of fundamental string behavior?
U+FDFC is a right-to-left Unicode character. It’s meant to be embedded in right-to-left text. You’re mixing left-to-right and right-to-left text.
From Wikipedia:
So the solution is to add a U+200E left-to-right mark after right-to-left currency symbols: