Percentage with a lot of extra decimal places

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
308
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have a User Form where I ask the user to input a number. This number then gets input into several cells across a few difference sheets.

Ultimately the number will be stored in the cells as a percentage, and I have already formatted the cells to hold a percentage with 2 decimal places. So, when my code inserts the number into the cell, the number must be a decimal number to the 4th decimal place. (For instance, if the user inputs '21.59', my code converts it to '.2159' before writing it into the proper cell.

Here is the code that runs when the user clicks a button on the User Form, after they have entered their number.

Code:
Private Sub MarkupApplyButton_Click()

Dim ConvertedValue As Single

ConvertedValue = Round(MarkupTextBox.Value / 100, 4)

Sheets("Cost Summary").Range("AN33").Value = ConvertedValue

End Sub

If the user inputs '21.59' as their number, this code seems to work. In Cell AN33, '21.59%' appears. HOWEVER, what appears in the formula bar when Cell AN33 is highlighted is '21.5900003910064%'

I don't understand why this is. Any ideas?

Perhaps this is not something to worry about -- maybe it will not affect the math that is going to be done on the sheet using this percentage. But just in case it is, I would really love for the number that appears in the cell to truly only have two decimal places. I'm certainly open to another way to go about the whole thing if it will solve the problem. TIA!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Use As Double instead of As Single.

PS.... Or don't use an intermediate variable, in the first place. The following would have worked just fine:

Sheets("Cost Summary").Range("AN33").Value = Round(MarkupTextBox.Value / 100, 4)
 
Last edited:
Upvote 0
AH! That did it. Wow, sometimes it's something so simple!! Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top