I have a that is generated from the diference of 2 numbers, but it return for exemple 0,07 for 7% and 0,5 for 50% i just want to fix to reach these goar, like 15,2% 13% and so on. How can I do t开发者_开发技巧hat? do c# has something embeded on CLR to do that?
You can use the Percentage Custom Numeric Format String. This will do it without you having to multiply yourself.
For example, you can do:
double value = 0.152;
string result = value.ToString("#0.##%");
If your locale is set to European (my guess based off the format you wrote), you'll get a string with the value of "15,2%".
You can also just use the Standard Percentage ("P") Format String, if you're happy with the default formatting.
Take a look there : Custom Numeric Format Strings
double number = .2468013;
Console.WriteLine(number.ToString("P", CultureInfo.InvariantCulture));
// Displays 24.68 %
Console.WriteLine(number.ToString("P",
CultureInfo.CreateSpecificCulture("hr-HR")));
// Displays 24,68%
Console.WriteLine(number.ToString("P1", CultureInfo.InvariantCulture));
// Displays 24.7 %
精彩评论