0

I am attempting to use string.Format to include a currency symbol and seeing an unexpected result.

See the following:

var textToReplace = "Final price is {0} {1}";
var output = string.Format(textToReplace, "Include MAD currency symbol here", "123.90");
output.Dump();

// Currency symbol is د.م.

Final price is د.م. 123.90

Strangely as I type this question, the SO question area automatically switch the currency symbol position with amount. Its bit hard to explain, try it yourself.

I would like to see the currency symbol followed by the amount. However I see the the amount followed by the currency symbol.

How can I explain this behaviour?

1
  • 2
    How can I explain this behaviour? symbol is RTL, so in fact it's before the price Commented Jan 28, 2020 at 9:59

1 Answer 1

3

The problem you're facing is that the symbol is RTL. The position is correct, but it gets rendered in the other way. You could try to add the Unicode \u200E. This will mark that the character should be Left-to-Right

for example:

var textToReplace = "Final price is {0} {1}";
var output = string.Format(textToReplace, "Include MAD currency symbol here\u200E", "123.90");
output.Dump();

Example: https://dotnetfiddle.net/zVegfA

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.