Solved

# Convert to percentage

Posted on 2011-10-31
367 Views
How would I convert a string to a percentage using C#?

Ex:
How would I convert 85, 73,10 to a percentage?
When I divide by 100, I get .85, .73, .10.
How do I make it 85%, 73%, 10%?
0
Question by:Isaac

LVL 22

Expert Comment

you could do a

yourString = yourString.Replace(",", "%,");
0

LVL 5

Author Comment

Wouldn't I then get the following results?
%85, %73,%10
0

LVL 22

Accepted Solution

no b/c it would look for comma placement and insert at that index replacing the comma with %,

making

85%, 73%, 10

i  guess that you would have to make sure to add a % at the very end of the string tho'
0

LVL 5

Author Comment

if it's comma replacement, how does it get rid of the "."?

Also, I guess I can just concatenate % at the end?
0

LVL 22

Expert Comment

don't divide by 100 just take the whole number and apply the string replacement.

there are a lot of ways to add at the end of the string-- choose whatever you like.
0

## Featured Post

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…