Convert a percentage to a decimal number

Page 1 of 1

4 Replies - 28735 Views - Last Post: 05 May 2011 - 02:26 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=153735&amp;s=d307dca50ed39f078d743bd09e151aa5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 e12451

Reputation: 0
• 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

• D.I.C Regular

Reputation: 7
• 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

#3 mrvbdude

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

Re: Convert a percentage to a decimal number

Posted 05 May 2011 - 09:44 AM

rainbow 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.

#4 lordofduct

• I'm a cheeseburger

Reputation: 2668
• Posts: 4,786
• 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"

#5 mrvbdude

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

Re: Convert a percentage to a decimal number

Posted 05 May 2011 - 02:26 PM

lordofduct, 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