[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Convert to percentage

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
Isaac
Asked:
Isaac
  • 3
  • 2
1 Solution
 
p_davisCommented:
you could do a

yourString = yourString.Replace(",", "%,");
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Wouldn't I then get the following results?
%85, %73,%10
0
 
p_davisCommented:
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
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
if it's comma replacement, how does it get rid of the "."?

Also, I guess I can just concatenate % at the end?
0
 
p_davisCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now