Reputation: 1068
I'm not sure if someone has asked this already but since I couldn't find the answer, I'll ask it again.
I'm trying to display a price with the dollar sign on the left, with no space between them. (Example: $10)
My following solution works if there would be a space between dollar sign and format argument, example: $ 10
<string name="deposit_amount_value">$ %1$s</string>
and then
String depositAmount = getResources().getString(R.string.deposit_amount_value, 10)
However, if I remove the space between dollar sign and format argument(similar to the follwoing example), it wouldn't work as I wish anymore.
<string name="deposit_amount_value">$%1$s</string>
How can I fix this inside the strings.xml file so I can show $10
instead of $ 10
Upvotes: 3
Views: 1696
Reputation: 614
In order to show the $ next to a variable code you can use the unicode value \u0024
<string name="deposit_amount_value">\u0024%1$d</string>
It is best to keep it inside of the string file in the event that you need to change currency symbol based on local, then your code and stay the same and just use different string.xml files.
Upvotes: 3