# convert percentage to decimals

Hello,
I would like to change percentage to decimal in C#. The number of decimals may vary.  For example here are 3 numbers.
91.5
84
90.48
I would like to show them as
9,15
8,4
9,048
How is best to do that?
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Senior .Net DeveloperCommented:
Can you clarify?

the commas look off.  Why would 84 = 8,4?  How would you change it back?

2.29304880?
20394.203940283?
34.2309482034092?
0.230402934?
10000?
Author Commented:
If there is a zero at the end it will not show.
So 100.00 will be shown 100
In percentage max number of decimals are 2, i.e. 90.48.   90.481 is not possible.
The percentage will be from 0 to 100. I want to change it to the scale 0-10.
Greetings
Senior .Net DeveloperCommented:

what does 5 %  mean on a scale of 0 - 10?  (0 or 1)?

As a starter:
``````Decimal d = 98.923;
Int Scaler = Math.Round(d/10, 0);
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Senior DeveloperCommented:
Personally, I'm a bit surprised with the choice to express percentage in the scale from 0 to 10. Usually it's 0-1 or 0 - 100.

Anyway, try the following code:

``````        private void button7_Click(object sender, EventArgs e)
{
decimal[] nums ={91.5m,84m,90.48m};

// convert to range 0 - 10 and remove trailing 0s allowing 3 digits after decimal point
foreach (decimal n in nums)
{
decimal x = n / 10;
string numberToPrint = x.ToString("G4");
System.Diagnostics.Debug.WriteLine(numberToPrint);
}
}
``````

Output will be:

``````9.15
8.4
9.048
``````
Author Commented:
Thank you. Sorry for late reply.
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.