Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I write code below in Consol Application:
Console.WriteLine("{0:C},10.5);
Console.ReadKey();

Print:10,50 ?
I expected:10,50 TL

Why display "?" instead of "TL"



Thanks...

What I have tried:

I used Culture Info but problem not solved
Posted
Updated 5-Feb-17 18:35pm
Comments
Garth J Lancaster 3-Feb-17 23:34pm    
you don't show us a couple of things that would be nice - like 'how' you use 'Culture', what the current culture is on your machine, or what 'TL' is. Are you for example using something like this below :-

Console.WriteLine(value.ToString("C", CultureInfo.CreateSpecificCulture("xx-yy")));

to set the 'Culture', where 'xx-yy' is the required Culture ?, for example, 'en-GB', 'en-US'

[edit 1 : is your Culture 'tr-TR' for Turkish ? - so 'TL' is 'Turkish Lira' ??] [/edit 1]

[edit 2 : something tells me you may need to set the 'TL' as the default currency symbol - see this link http://stackoverflow.com/questions/951689/how-to-set-currencysymbol-on-readonly-cultureinfo-numberformat particularly the post from Jon Skeet

which means you need :-

var original = CultureInfo.GetCultureInfo("tr-TR");
var mutableNfi = (NumberFormatInfo)original.NumberFormat.Clone();
mutableNfi.CurrencySymbol = "TL";
double price = Convert.ToDouble(retailerProduct.Price);
stringBuilder.Append(price.ToString("C", mutableNfi));

(Ref : http://stackoverflow.com/questions/16710418/get-latest-turkish-currency-symbol ) [/edit 2]

[edit 3 : apparently, the '?' is printed because whatever the symbol is for 'Turkish Lira', it is not available in the font you are using, ie, if writing to the Console, its likely to be 'Lucinda Console' or such [/edit 3]
xkadir 4-Feb-17 17:10pm    
Thanks for reply,Garth J Lancaster
My culture is (tr-TR) Turkish
Two examples I made, for Culture Info but not display "TL":
Ex 1:
double price=10.50;
Console.WriteLine(price.ToString("C", CultureInfo.CreateSpecificCulture("tr-TR")));
Console.ReadKey();
Output : 10,50 ?
Ex 2:
double price=10.50;
Console.WriteLine("Ürünün Fiyatı : {0} ", price.ToString("c", new CultureInfo("tr-TR")));
Console.ReadKey();
Output : 10,50 ?
---------------------------------------------
The problem is solved like the example you gave from Jon Skeet;display "TL"
var original = CultureInfo.GetCultureInfo("tr-TR");
var mutableNfi = (NumberFormatInfo)original.NumberFormat.Clone();
mutableNfi.CurrencySymbol = "TL";
double price = 10.50;
Console.WriteLine(price.ToString("C", mutableNfi));
Output : 10,50 TL
But my wish is not this way.
I am the teacher and I need to show it in the simplest way.For example,
Console.WriteLine("{0:C},10.50);
Console.ReadKey();
Output : 10,50 ?
I want :10,50 TL
But I can not show my wish on my computer(Win10,VS2015 Enterprise)
Garth J Lancaster 4-Feb-17 21:23pm    
'simplest way' - but does that equal commercial reality ? if you had students who were going to make it a career, what would make sense to teach them ?

you could :-

1) find a font that has a rune/glyph/symbol for 'TL' and use that in your console program - commercial reality ? ok if you're only ever outputting to console, its not that 'simple' either

2) use Peter's suggestion - which doesn't handle ',' vs '.' for example

3) Write your own class - just to handle Turkish currency to the console - really, I hear 'dont re-invent the wheel' in the back of my head

perhaps the 'simplest way' is to write a wrapper or facade around Jon Skeet's code

var original = CultureInfo.GetCultureInfo("tr-TR");
var mutableNfi = (NumberFormatInfo)original.NumberFormat.Clone();
mutableNfi.CurrencySymbol = "TL";
double price = 10.50;
Console.WriteLine(price.ToString("C", mutableNfi));

call it OutputCurrencyAsTurkishForConsole or something, and present that to your students - realise the fact that given you're using 'console' output and cant/dont want to change the font and/or cant find a font with the desired symbol anyway, that represents the best trade-off in 'simple' vs 'commercial reality'

(or as an alternative to Jon Skeet's code, write a wrapper/facade for this

Console.WriteLine(price.ToString("C", CultureInfo.CreateSpecificCulture("tr-TR")));

that deletes the '?' character and appends 'TL')

Do I still hear you saying 'no, simple' in the background ? - Im sorry, given requirements (you wish to output a properly formatted number in the Turkish format/locale to the console) vs constraints of the system you're using, a wrapper/facade around either pieces of code is the 'simplest' option that represents commercial reality
xkadir 4-Feb-17 22:39pm    
Thanks for your meaningful answers,Garth J Lancaster
My students are not at that level yet.They are at the beginning level.They will learn when the time comes.
As you said, it seems to be solving my problem finding a suitable font that a rune/glyph/symbol for 'TL'
Peter Leow 4-Feb-17 1:38am    
To avoid all the hassle, why not just
string currencySymbol = "TL";
Console.WriteLine("{0:N2} {1}", 10.5, currencySymbol);

1 solution

Try This

double value = 10.5;

Console.WriteLine(value.ToString("C3", CultureInfo.CreateSpecificCulture("tr-TR")));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900