[C#] Displaying Currency

Toz

Elite Member
Jr. VIP
Joined
Oct 24, 2011
Messages
3,219
Reaction score
3,625
Hello BHW,

I'm trying to resolve a minor issue in which the USD sign ($) is failing to display, when using the following code:

Code:
string test = String.Format("{0:C}", 123.21);
Console.WriteLine(test);

My output is showing as this:
9OmclS.jpg


Anyone know why I'm getting this small, rectangle-encased question-mark? Shouldn't it display a dollar sign, instead?
 
This answer is probably not what you're looking for, but I'm gonna post it anyway:

Do you plan on building applications with a GUI? If so, skip the console and start building in WinForms or WPF. I learned a little bit using the console, and got bored, and started building with interfaces. It only takes a few clicks with WinForms to drag in a button that runs your c# code, and it's easy to build a Message Box (alert) that outputs the results of your code. If you tried that code and outputted in a message box I'm pretty sure it would display normally (with a $ sign), from the quick look I gave at your code.

I'll probably get crucified by any die-hard c-sharpers, but I got into bot building to make money, so skipping console development and going straight for simple GUI bots made sense, it may or may not be the best solution for you.
 
This answer is probably not what you're looking for, but I'm gonna post it anyway:

Do you plan on building applications with a GUI? If so, skip the console and start building in WinForms or WPF. I learned a little bit using the console, and got bored, and started building with interfaces. It only takes a few clicks with WinForms to drag in a button that runs your c# code, and it's easy to build a Message Box (alert) that outputs the results of your code. If you tried that code and outputted in a message box I'm pretty sure it would display normally (with a $ sign), from the quick look I gave at your code.

I'll probably get crucified by any die-hard c-sharpers, but I got into bot building to make money, so skipping console development and going straight for simple GUI bots made sense, it may or may not be the best solution for you.
MOTHERFUCKER!

Not you... But you just brought me face-to-face with something I've been wrestling my brain with for the last week that I've been studying this language...
Basically every tutorial series I've seen, begins with the Console, which is fine, I suppose, but I never felt it was really related to anything that directly correlates to what I'm trying to do. Like you, I'm interested in building bots to turn a profit and that will help people out. It's because of this, that I really appreciate your input. Now don't get me wrong.. I've learned quite a bit! It's just that I really want to get into the concept of working with forms and GUIs and buttons and whatnot. I know that what I've been learning will help my transition into forms be easier, but I feel like I'm going to need to relearn a bunch of stuff, as it applies to working with forms.

In either case, I'm doing 2 separate training tutorials and I will see both through to the end, and then will dive into forms. If not for anything else, the Console training is helping me to learn the syntax, operators, working with methods, strings, etc.. I'll stick it out for about another week. By then, I should have finished both tuts. And then onto forms. Any good resources you can point me to?

Thanks for your insight!
 
  • Like
Reactions: X
Honestly I can't think of any WinForms/WPF specific training that was a singular source that I can recommend (mostly lots of cursing, sweating, Stack Overflowing, and testing... probably not the most efficient approach). But anything you can do in console you can easily warp into WinForms (or a little more work to get into WPF), but I can say that this info: https://www.amazon.com/HTTP-Programming-Recipes-C-Bots/dp/0977320677 was life-changing (as much as programming tutorials can be life-changing lol).
 
  • Like
Reactions: Toz
+1 For always going with GUI's, even if console is enough for a quick job i prefer GUI's too.
 
  • Like
Reactions: Toz
You should still try to resolve this issue even if you're going to go with GUI. You're dealing with web bots, so eventually you're going to have to deal with text manipulation. Slap together a quick fix for now if you're in a hurry, but investigate this issue later when you have time. These kind of problems are great for strengthening your understanding of the language in which you are programming.

Anyways; looks like you're using the currency format ":C" and it looks like C#'s trying to put in a currency symbol, but console doesn't support unicode/utf8, it only supports ASCII.

Perhaps check your "Region" settings (in Control Panel) to and double check your currency symbol?

Alternative: Try to print
Code:
Thread.CurrentThread.CurrentCulture
into a file. See what you get.




die-hard c-sharpers
LOL
 
console doesn't support unicode/utf8, it only supports ASCII.
Interesting. I will be revisiting this. Thank you.
 
Interesting. I will be revisiting this. Thank you.
No problem.

Take a look at "chcp" command-line command if you've gone off the deep end and become interested in command prompt character encoding, lol.
 
  • Like
Reactions: Toz
MOTHERFUCKER!

Not you... But you just brought me face-to-face with something I've been wrestling my brain with for the last week that I've been studying this language...
Basically every tutorial series I've seen, begins with the Console, which is fine, I suppose, but I never felt it was really related to anything that directly correlates to what I'm trying to do. Like you, I'm interested in building bots to turn a profit and that will help people out. It's because of this, that I really appreciate your input. Now don't get me wrong.. I've learned quite a bit! It's just that I really want to get into the concept of working with forms and GUIs and buttons and whatnot. I know that what I've been learning will help my transition into forms be easier, but I feel like I'm going to need to relearn a bunch of stuff, as it applies to working with forms.

In either case, I'm doing 2 separate training tutorials and I will see both through to the end, and then will dive into forms. If not for anything else, the Console training is helping me to learn the syntax, operators, working with methods, strings, etc.. I'll stick it out for about another week. By then, I should have finished both tuts. And then onto forms. Any good resources you can point me to?

Thanks for your insight!
Honestly I can't think of any WinForms/WPF specific training that was a singular source that I can recommend (mostly lots of cursing, sweating, Stack Overflowing, and testing... probably not the most efficient approach). But anything you can do in console you can easily warp into WinForms (or a little more work to get into WPF), but I can say that this info: https://www.amazon.com/HTTP-Programming-Recipes-C-Bots/dp/0977320677 was life-changing (as much as programming tutorials can be life-changing lol).


my course coming , I'm creating C# web and desktop automation course for beginners :)
 
  • Like
Reactions: Toz
string test = String.Format("{0:C}", 123.21);
Console.WriteLine(test);

errrr

Code:
console.WriteLine("$123.21");
[/quote]

all good :)
 
Back
Top