0

In C# code I have a floating point variable number that I want presented as a string but I want it formatted in a particular way. if I have a float number, like, 0.532492829839, for example and I want it represented in C# code as "53.24%", how would I do that? I imagine it would be done using IFormatProvidre and float.parse. But I have not done it before. First of all, I guess I should multiply the number by 10, but how would I pick a number of decimal place?

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by nmaillet
1
float A = 0.532492829839;
A = 100 * A
textbox1.text = string.format("00.00", A.ToString()) + "%"

I have not tested this but it should look something liks this I guess

0
textbox1.text = string.format("00.00", A.ToString()) + "%"

Why would you append a string to a string format (and your format is wrong :))

textbox1.Text = String.Format("{0:00.00}%", A.ToString());
0

You shouldn't be converting the float variable to a string. This will not allow the proper formatting:

double A = 0.532492829839;
string.Format("{0:0.00}%", A * 100.0);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.