Regulus's stupid C# questions thread

Soldato
Joined
18 Aug 2006
Posts
10,048
Location
ChCh, NZ
Ok, I started learning C# 5 days ago and have made very satisfactory progress. I keep struggling on silly little points but I managed to figure stuff out eventually. I wanted to have a thread whereby I can ask the experience guys on here some stuff I can't get working

I'm busy doing a project. I'm writing a ticketing system that sits on a SQL machine. I've installed the .NET framework in my 3 PC Lan and all the computers "talk" to the SQL machine. Imagine the PC's are the users ordering movie tickets, theather tickets etc. The program keeps track of how many tickets sold, what shows (there are only two),money earned and how many seats still left. It displays all the results to a datagrid and updates itself autamatically everytime a transaction is entered. It's very basic stuff and probably awful code but it works!

But, I have a silly problem. Laughable actually. I don't know how to display pennies. As in £6,23p.

My tickets cost 7.75 each, declared as integers. It refuses to display the pennies bit. Just throws an exception. I've tried double, float, decimal (which rounds it to the nearest £££). So if you use my system and pay with a tenner, you're pretty much screwed! Instead of getting back £2.25, you'll only get £2.00

I hope I explained this properly. Please be kind, 5 days experience here....
 
Writing structs is just a tad above my abilities at the moment.

Show me how you would write a program that will subtract 6.66 from 10 and display the result to a textbox.
 
NathanE said:
double num;

num = 10f - 6.66f;

myTextbox.Text = String.Format("{0:c}", num);

Thanks!!! got it working now!

Although still don't understand the String.Format part. I'll just take it at face value for now
 
Back
Top Bottom