4 Replies - 7995 Views - Last Post: 05 May 2011 - 02:26 PM Rate Topic: -----

#1 e12451  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-February 10

Convert a percentage to a decimal number

Posted 03 February 2010 - 12:57 PM

I want to know how to convert a percentage rate such as 4.5% into a decimal number in your code editor in V 2008.

For example, the user input is 4.5%. Is there any function available to convert is to 0.045? Thanks,
Is This A Good Question/Topic? 0
  • +

Replies To: Convert a percentage to a decimal number

#2 rainbow evil  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 308
  • Joined: 15-July 09

Re: Convert a percentage to a decimal number

Posted 03 February 2010 - 04:59 PM

you could make a function in a module. The code would really be quite simple, here is an example I've made:
Function ToDecimal(Percentage As String) As Double

Percentage = Left(Percentage, Len(Percentage) - 1)   'removes percentage sign'

ToDecimal = Val(Percentage) / 100    'makes the percentage string a number using Val(), divides that by'
                                     '100 to get a decimal and then makes the function return that value'
End Function



Hope this helps

This post has been edited by rainbow evil: 03 February 2010 - 05:04 PM

Was This Post Helpful? 0
  • +
  • -

#3 mrvbdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-May 11

Re: Convert a percentage to a decimal number

Posted 05 May 2011 - 09:44 AM

View Postrainbow evil, on 03 February 2010 - 04:59 PM, said:

you could make a function in a module. The code would really be quite simple, here is an example I've made:
Function ToDecimal(Percentage As String) As Double

Percentage = Left(Percentage, Len(Percentage) - 1)   'removes percentage sign'

ToDecimal = Val(Percentage) / 100    'makes the percentage string a number using Val(), divides that by'
                                     '100 to get a decimal and then makes the function return that value'
End Function



Hope this helps



Hi

Thanks for the great example, what does "Left" mean in your code and it gives me an error.
Was This Post Helpful? 0
  • +
  • -

#4 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2533
  • View blog
  • Posts: 4,633
  • Joined: 24-September 10

Re: Convert a percentage to a decimal number

Posted 05 May 2011 - 09:52 AM

It's grabs the 'left' part of a string up to the length passed as the second parameter.

Left("hello", 3)

will return

"hel"
Was This Post Helpful? 0
  • +
  • -

#5 mrvbdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-May 11

Re: Convert a percentage to a decimal number

Posted 05 May 2011 - 02:26 PM

View Postlordofduct, on 05 May 2011 - 09:52 AM, said:

It's grabs the 'left' part of a string up to the length passed as the second parameter.

Left("hello", 3)

will return

"hel"


Ohk...cheers. I fixed my code now :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1