Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code:

double somename = 1.50;
label.Contnet = somename;

My label shows its as 1.5. The zero isn't displayed. How can I avoid this?
Posted
Updated 7-Dec-09 8:35am
v2

You have 2 options:

  1. Convert somename to a string first and make sure to format it (string.Format) with 2 decimal places.
  2. Bind the label content to the somename value and use StringFormat in the binding expression to format it with 2 decimal places.
 
Share this answer
 
label.Content = somename.ToString("0.00");

I think "d2" would do the same thing, but my memory is a little fuzzy on standard format strings.
 
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