Rob P Rob P - 1 year ago 87 Question

How can I set an output value to 2 decimal places in Visual Studio?

Im putting together a basic Gross Profit Calculator in Visual Studio and need the output to show as a £ value, ie to 2 decimal places.

I have tried this so far:

String.Format("{0:0.00}", TextBox3.Text = CStr(sale))

where TextBox3 is the output for the calculation. However on using this, nothing happens and the box remains empty and I can't work out why!

Answer Source

Your syntax is not correct, re-write your code this way:

TextBox3.Text = String.Format("{0:0.00}", sale)

The String.Format's result wasn't being assigned to anything.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download