-2

I have a float value that I want to put into a label.Text.

The float can be positive or negative, I am not sure the best way to do so. I was looking at String.Format but I am not sure how to use it properly.

Demonicpenguin
  • 113
  • 1
  • 3
  • 13

2 Answers2

1

Why don't you simply convert the float to string using ToString()

textbox1.Text = myFloat.ToString();

And if you are more interested in format method simply go through this

Kavindu Dodanduwa
  • 12,193
  • 3
  • 33
  • 46
  • 1
    This should be the accepted answer. Unless I'm missing something, OP simply stated they want to display a float value in a textbox. Jenish's answer will always display the value as negative. – Reticulated Spline Feb 14 '15 at 06:09
0

if your variable is called value holding float value then you can use it like following.

Label.Text = value>0? String.Format("-{0}", value ):String.Format("{0}", value );

Here is working fiddle for testing and playing with string.Format() => link

Jenish Rabadiya
  • 6,708
  • 6
  • 33
  • 62