# Convert a percentage to a decimal number

Page 1 of 1

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

### #1 e12451

• New D.I.C Head

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

Was This Post Helpful? 0

### #3 mrvbdude

• New D.I.C Head

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.
Was This Post Helpful? 0

### #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"
Was This Post Helpful? 0

### #5 mrvbdude

• New D.I.C Head

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
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }