Solved

# Is there a way to format a percentage of a value without doing any math?

Posted on 2006-04-25
230 Views
In VS 2005, is there a way to format a value by percentage, like: Value = 50% of Value without doing any math (5 = 50% of 10)?

Thanks
0
Question by:grouchyfd

LVL 85

Accepted Solution

Not sure exactly what you are asking here...

Like this?

Dim value As Integer = 10
Dim str As String = (0.5 * value).ToString("0")
MsgBox(str)

You have to do the "math" by multiplying by .5 to get 50%.  There isn't anything you could place in the ToString() portion that would do this for you if that is what you are asking...
0

LVL 9

Assisted Solution

Dim str As String =  (5.0 / 10.0).ToString("00%")
It will not work without math, unless you write a small function

Private Function Percent(ByVal v As Double, ByVal v100 As Double) As String
Return (v / v100).ToString("00%")
End Function

Dim str As String =Percent(5.0,10.0) ' this is as math-free as it gets

Jack.net

0

Author Comment

Thank you both. This is what I was looking for. One time I can just incorporate the code, the other I can make a public/private function  so an app. can do the same thing several times.
0

## Featured Post

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…