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 that? do c# has something embeded on CLR to do that?
If there IS a decimal point, move it to the right the same number of places that there are 0s. When dividing by 10, 100, 1000 and so on, move the decimal point to the left as many places as there are 0s. So when dividing by 10, move the decimal point one place, by 100 two places, by 1000 three places and so on.
To change a decimal to a percent, we multiply by 100. This is the same as moving the decimal point two places to the right. To change the decimal 0.22 to a percent, we move the decimal point two places to the right and get 22%.
Make use of the Free Decimal to Percent Calculator to change decimal value 0.15 to its equivalent percent value 0.0015% in no time along with the detailed steps.
Both mean that you have 52 parts out of 100. You move the decimal point two places to the right to show hundredths. Percent is “out of 100,” so the % sign is the same as two decimal places: 0.52 × 100 = 52 .
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 %
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With