# Convert an Integer into percent

I have an asp.net 2.0 application.  A value of 10 is stored in our SQL database to represent a percentage we charge a client.  10 is being passed to our application as an integer.
My question is - how would I convert the datafield value of 10 to 0.1 to be used in a mathmatical routine? or
How would I convert the the datafield value of 5 to 0.05 .....
``````Assume my variable is MyDatabaseValue which is 10

Revenue.Text = String.Format("{0:c}", 1000 * MyDatabaseValue)
``````
###### Who is Participating?
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.

Chief Technology OfficerCommented:
You can try the String.Format("{1:P}", 1000 * MyDatabaseValue).
Chief Technology OfficerCommented:
Sorry I see now what you are asking.  The {1:P} means to make the number a percentage, but you are wanting a currency amount times a percentage.

Just do this:

Revenue.Text = String.Format("{0:c}", 1000 * MyDatabaseValue / 100)
Chief Technology OfficerCommented:
You can also make sure it comes out of the DB the way you want it by doing this:

SELECT CAST(datafieldvalue * 1.0/100 AS Money) AS percentage
FROM TableName
Commented:

Change the value in the business-layer OR in the data-layer:

Revenue.Text = String.Format("{0:c}", 1000 * (MyDatabaseValue / 100))

Or create a function for it
Private Function ToPct(nValue as object) as Double
If nValue Is dbNull.value Then
Return 0
ElseIf Not IsNumeric(nValue) Then
Return 0 'Or throw an error
Else
Return nValue / 100
End If
End Function
Revenue.Text = String.Format("{0:c}", 1000 * ToPct(MyDatabaseValue))

- Data-layer:
Change your SELECT statement to something like this:
SELECT CONVERT(float, MyDatabaseValue)/100 AS MyDatabasePercent FROM tablename

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Author Commented:
thank you - This worked to convert 10 to 0.1 and the calculation worked correctly
Chief Technology OfficerCommented:
Glad you found what you were looking for.

Given I gave same answers 30 minutes ago, please advise what made mine incorrect so I can better answer this question for others in the future.  Just curious.
###### 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
ASP.NET

From novice to tech pro — start learning today.